QTP 通过URL地址下载文件到本地
2012-08-23 10:24
447 查看
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.
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
相关文章推荐
- Java 通过URL地址下载文本内容到本地文件中
- c#通过URL地址从服务器上下载文件
- 根据文件网络地址url通过输出输入流下载文件
- 爪哇国新游记之二十八----从url指定的地址下载文件到本地
- JAVA通过访问页面中的URL实现Http文件下载到本地
- asp.net(c#)从url网络地址下载图片或文件到本地硬盘
- 根据url地址下载文件到本地,返回本地文件地址
- 根据url地址下载文件到本地,返回本地文件地址
- JAVA通过访问页面中的URL实现Http文件下载到本地
- 从URL地址将文件按行下载到本地
- ASP.NET获取远程网页下载到本地文件,通过URL生成静态文件的做法
- JAVA 实现通过URL下载文件到本地库
- 通过SecureCRT下载远程Linux服务器上的文件到本地Windows
- 通过URL下载文件
- 通过Mac Os 共享url,让别人从你电脑下载文件
- 下载(二)客户端通过C# 代码直接从服务器下载文件到本地
- Python---对html文件内容进行搜索取出特定URL地址字符串,保存成列表,并使用每个url下载图片,并保存到硬盘上,使用bs4,beautifulsoup模块
- 通过zssh在服务器和本地之间上传和下载文件
- MFC通过URL下载并保存文件代码
- Android安卓根据地址下载文件并保存到本地(HttpDownload)