Forum Discussion

sarfraz07's avatar
sarfraz07
Occasional Contributor
15 years ago

How to Implement callback for file downloading?

Hello,

I wrote a script that downloads file from web using file URL. I have an ActiveXObject of following type.



var objHTTP = new ActiveXObject("MSXML2.XMLHTTP");  

objHTTP.open("GET", strFileURL, false);



It works perfect for small size file says, file size less than 100MB.  But when I try to download file with size greater than 100MB my script hanged. Then I tried,    



objHTTP.open("GET", strFileURL, true);



but in this case we have to implement a callback function. I don't know how to implement callback and then use it. Can somebody help me. I am using TestComplete 7. Script that I wrote;




  var objHTTP = new ActiveXObject("MSXML2.XMLHTTP");

  objHTTP.open("GET", strFileURL, true);

  objHTTP.onreadystatechange = Callback;

  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; 

  } 


I don't know how to implement Callback function. Can somebody provide me implementation?

Thanks

2 Replies

  • Hi Sarfraz,



    As an alternative, you can try recording a test that downloads a file using a browser or download manager.



    As for the script, we are not aware of such an issue. Note that TestComplete does not have its own means to download files. The script uses Microsoft OLE objects to accomplish the task. If you have problems with it, please contact Microsoft Support or search through Microsoft technical resources.