博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
QTP 通过URL地址下载文件到本地(转)
阅读量:5121 次
发布时间:2019-06-13

本文共 2154 字,大约阅读时间需要 7 分钟。

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 on  and  .
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

 

转载于:https://www.cnblogs.com/ellie-test/p/4518998.html

你可能感兴趣的文章
[转]: 视图和表的区别和联系
查看>>
Regular Experssion
查看>>
图论例题1——NOIP2015信息传递
查看>>
uCOS-II中的任务切换-图解多种任务调度时机与问题
查看>>
CocoaPods的安装和使用那些事(Xcode 7.2,iOS 9.2,Swift)
查看>>
Android 官方新手指导教程
查看>>
幸运转盘v1.0 【附视频】我的Android原创处女作,请支持!
查看>>
UseIIS
查看>>
集合体系
查看>>
vi命令提示:Terminal too wide
查看>>
引用 移植Linux到s3c2410上
查看>>
MySQL5.7开多实例指导
查看>>
[51nod] 1199 Money out of Thin Air #线段树+DFS序
查看>>
poj1201 查分约束系统
查看>>
Red and Black(poj-1979)
查看>>
分布式锁的思路以及实现分析
查看>>
腾讯元对象存储之文件删除
查看>>
jdk环境变量配置
查看>>
安装 Express
查看>>
包含列的索引:SQL Server索引的阶梯级别5
查看>>