0

我正在使用 TestComplete 7。我正在编写一个从 Web 下载文件并将下载的文件放入商店的测试。我正在使用 C++ 脚本来实现这一点。但我有问题。我不知道如何使用 C++ 脚本中的 URL 从 Web 下载文件。有人可以给我任何建议吗

4

1 回答 1

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); 
} 
于 2011-04-27T12:59:12.580 回答