zoukankan      html  css  js  c++  java
  • QTP 通过URL地址下载文件到本地(转)

    While automation, you may 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, managing the Save As box, etc. This many a time causes sync issues. Moreover, we end up automating something that is not at all needed to be automated or tested. In this situation, all you need is 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 download in the background. You just need to capture the download URL from the potential download link and call this function and you will find the download 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.
    Sub utilDownloadFile(strFilePath, strURL)  
      
       Set WinHttpReq = 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.   
       'You can ignore this line for first attempt but add it if your download is hindered, X is IP and Z is Port  
      
       temp = 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.ResponseBody  
      
       Set oStream = createobject("Adodb.Stream")  
       Const adTypeBinary = 1  
       Const adSaveCreateOverWrite = 2  
      
       oStream.type = adTypeBinary  
       oStream.open  
       oStream.write strResult  
       oStream.savetofile strFilePath, adSaveCreateOverWrite  
      
    End Sub  
  • 相关阅读:
    分享15个Linux 实用技巧,提高工作效率
    隐藏搜索框:CSS 动画正反向序列
    js检测开发者工具是否打开,防止别人恶意调试我们的代码
    Js实现元素右滑回弹效果(基于Uniapp)
    css ::marker伪元素,修改li的项目符号颜色,字号字体
    Jump Game II
    Google 面经 09/26
    Word Search
    Remove Duplicates from Sorted List
    Remove Duplicates from Sorted List II
  • 原文地址:https://www.cnblogs.com/ellie-test/p/4518998.html
Copyright © 2011-2022 走看看