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 =
Const adSaveCreateOverWrite = oStream.type = adTypeBinary
oStream.open
oStream.write strResult
oStream.savetofile strFilePath, adSaveCreateOverWrite End Sub

QTP 通过URL地址下载文件到本地(转)的更多相关文章

  1. python-根据URL地址下载文件

    博主个人网站:https://chenzhen.online 使用Python中提供的urllib.request下载网上的文件 #coding=utf-8 """ 目标 ...

  2. URL地址下载图片到本地

    package test.dao; import eh.base.dao.DoctorDAO; import eh.entity.base.Doctor; import junit.framework ...

  3. 爪哇国新游记之二十八----从url指定的地址下载文件到本地

    package download; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; ...

  4. 在MFC中通过访问IP地址下载文件到本地

    void CDownLoad::OnBnClickedOk() { // TODO: 在此添加控件通知处理程序代码 CDialogEx::OnOK(); UpdateData(TRUE); CStri ...

  5. java根据图片的url地址下载图片到本地

    package com.daojia.haobo.aicircle.util; import sun.misc.BASE64Encoder; import java.io.*; import java ...

  6. 通过指定的 url 去网络或者文件服务器下载文件到本地某个文件夹

    /** * 从网络Url中下载文件 * @param urlStr 指定的url * @param fileName 下载文件到本地的名字 * @param savePath 本地保存下载文件的路径 ...

  7. 根据文件url,下载文件到本地

    /// <summary> /// 根据文件url,下载文件到本地 /// </summary> /// <param name="fileUrl"& ...

  8. C#使用WebClient下载文件到本地目录

    C#使用WebClient下载文件到本地目录. 1.配置本地目录路径 <appSettings> <!--文件下载目录--> <add key="Downloa ...

  9. Java远程下载文件到本地(http协议和ssh2协议)

    Java中java.io包为我们提供了输入流和输出流,对文件的读写基本上都依赖于这些封装好的关于流的类中来实现.前段时间遇到了以下两种需求: 1.与某系统对接,每天获取最新的图片并显示在前端页面.该系 ...

随机推荐

  1. Codeforces 1093C (思维+贪心)

    题面 传送门 题目大意: 有一个长n(n为偶数)的序列a 已知a满足 \(a_1≤a_2≤⋯≤a_n\) 给出一个长度为\(\frac{n}{2}\) 的序列b,定义\(b_i=a_i+a_{n-i+ ...

  2. [JSOI2007]建筑抢修(贪心+后悔)

    [JSOI2007]建筑抢修(贪心+后悔) 洛谷题目传送门 吐槽 这是一道经典的贪心后悔的题目 做过贪心加后悔的题目的应该一眼可以看出来 解题思路 首先按倒塌时间T2排序,再从1枚举到n,能修就修,发 ...

  3. [JavaScript深入系列]JavaScript深入之执行上下文栈(转载)

    顺序执行? 如果要问到 JavaScript 代码执行顺序的话,想必写过 JavaScript 的开发者都会有个直观的印象,那就是顺序执行,毕竟: var foo = function () { co ...

  4. ASE Alpha Sprint - backend scrum 10

    本次scrum于2019.11.15在sky garden进行,持续30分钟 参与人: Xin Kang, Zhikai Chen, Jia Ning, Hao Wang 请假: Lihao Ran, ...

  5. smbd - 向客户提供SMB/CIFS服务的服务器

    总览 SYNOPSIS smbd [-D] [-F] [-S] [-i] [-h] [-V] [-b] [-d <debug level>] [-l <log directory&g ...

  6. 二、jquery Try{}catch(e){}

    一.Try{}catch(e){} try{ $.each($("div"),function(i,item){ if(...){ throw("异常信息"); ...

  7. 不小心执行 rm -f,该如何恢复?

    每当我们在生产环境服务器上执行rm命令时,总是提心吊胆的,因为一不小心执行了误删,然后就要准备跑路了,毕竟人不是机器,更何况机器也有 bug,呵呵. 那么如果真的删除了不该删除的文件,比如数据库.日志 ...

  8. CSAW CTF Qualification Round 2018 - shell->code

    原题 Linked lists are great! They let you chain pieces of data together. nc pwn.chal.csaw.io 9005 链接:h ...

  9. Vue:子组件如何跟父组件通信

    我们知道,父组件使用 prop 传递数据给子组件.但子组件怎么跟父组件通信呢?这个时候 Vue 的自定义事件系统就派得上用场了. 使用 v-on 绑定自定义事件 每个 Vue 实例都实现了事件接口,即 ...

  10. java下载文件demo

    java通过http方式下载文件 https://www.cnblogs.com/tiancai/p/7942201.html