我正在使用TestComplete 7.我正在编写一个从web下载文件并将下载的文件放入Stores的测试。我正在使用C ++脚本来实现这一目标。但我有问题。我不知道如何使用C ++脚本中的URL从Web下载文件。有人可以给我任何建议
答案 0 :(得分:0)
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);
}