QTP download files to local (go) via URL address

Source: Internet
Author: User

While automation, the come to situations where you need to need to download a file on clicking a link. This generally involves a lot of User Interface (GUI) overhead like syncing the download box, clicking the buttons, Managin G The Save as box, etc. This many a time causes sync issues. Moreover, we end up automating something, which is not at all needed to be automated or tested. In this situation, all need are a code snippet in Visual Basic for Quick Test Professional that automatically downloads The file in the background without the need of any GUI appearances. You just need to provide the download link and the file path in your system. The function "Funcdownloadfile" below takes the file path and the download link as parameters in String and performs the D Ownload in the background. You just need to capture the download URL from the potential download link and call this function and you'll find the Do Wnload completed at the specified path. the function supports AuthenticaTed downloads and proxy settings. The function is based Onadodb STREAM object and winhttp API from Microsoft.
Subutildownloadfile (strFilePath, strURL)SetWinhttpreq =CreateObject("winhttp.winhttprequest.5.1")       'winhttpreq.setproxy httprequest_proxysetting_proxy, "xxx.xxx.xxx.xxx:zzzz"   'Required only if your Internet routes through a proxy.   Not required in 90% cases.    'can ignore this line for first attempt but add it if your download are hindered, X is IP and Z is PortTemp= Winhttpreq.open ("POST", strURL,false)          'winhttpreq.setcredentials "Username", "Password", Httprequest_setcredentials_for_server   'Required only if the file download server Required authentication. Not required in 90% cases.  Change Username and Password Wuth actuals. winhttpreq.send () winhttpreq.waitforresponse strresult=Winhttpreq.responsebodySetOStream =CreateObject("ADODB.stream")     ConstadTypeBinary =1     ConstAdsavecreateoverwrite =2Ostream.type=adtypebinary ostream.open ostream.write strresult ostream.savetofile strFilePath, AdSaveCreateOverWrite End Sub  

QTP download files to local (go) via URL address

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.