Unit testing 从web下载文件并将其放入TestComplete的存储中
我使用的是TestComplete7。我正在编写一个测试,从web下载文件,并将下载的文件放入存储区。我正在使用C++脚本来实现这一点。但我有问题。我不知道如何用它的URL在C++脚本中下载文件。谁能给我一些建议吗Unit testing 从web下载文件并将其放入TestComplete的存储中,unit-testing,testing,testcomplete,Unit Testing,Testing,Testcomplete,我使用的是TestComplete7。我正在编写一个测试,从web下载文件,并将下载的文件放入存储区。我正在使用C++脚本来实现这一点。但我有问题。我不知道如何用它的URL在C++脚本中下载文件。谁能给我一些建议吗 function Test(){ // Specify the names of the source and destination files var strFileURL = "http://www.automatedqa.com/file to get"; var
function Test(){
// Specify the names of the source and destination files
var strFileURL = "http://www.automatedqa.com/file to get";
var strHDLocation = "c:\\temp\\filename";
// Download the file
var objHTTP = new ActiveXObject("MSXML2.XMLHTTP");
objHTTP.open("GET", strFileURL, false);
objHTTP.send();
while((objHTTP.readyState != 4) && (objHTTP.readyState != 'complete')) {
Delay(100);
}
if (200 != objHTTP.Status) {
Log.Error("The " + strFileURL + " file was not found." + " The returned status is " + objHTTP.Status);
return;
}
var objADOStream = new ActiveXObject("ADODB.Stream");
objADOStream.Open();
objADOStream.Type = 1; //adTypeBinary
objADOStream.Write(objHTTP.ResponseBody);
objADOStream.Position = 0; //Set the stream position to the start
var objFSO = new ActiveXObject("Scripting.FileSystemObject");
if (objFSO.FileExists(strHDLocation)) objFSO.DeleteFile(strHDLocation)
objADOStream.SaveToFile(strHDLocation);
objADOStream.Close();
Files.Add(strHDLocation);
}