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. 用Emacs编写mybatis

    用Emacs编写mybatis */--> code {color: #FF0000} pre.src {background-color: #002b36; color: #839496;} ...

  2. Codeforces - 1088B - Ehab and subtraction - 堆

    https://codeforc.es/contest/1088/problem/B 模拟即可. #include<bits/stdc++.h> using namespace std; ...

  3. vue2.0在IE11无法打开的解决办法

    npm 安装bebel-polyfill npm install --save-dev babel-polyfill 在webpack.base.conf.js文件中将 module.exports ...

  4. Java加密与解密的艺术 读书心得

    现在项目中加密与解密的方式很多,很早就想整理一下Java中加密与解密的方式,读完<<Java加密与解密的艺术>>一书.借此机会梳理一下这方面的知识点 一.基础普及 安全技术目标 ...

  5. JavaScript中的方法和属性

    书读百遍其义自见 学习<JavaScript设计模式>一书时,前两个章节中的讲解的JavaScript基础知识,让我对属性和方法有了清晰的认识.如下是我的心得体会以及部分摘录的代码. 不同 ...

  6. unity DOTween Pro的使用--简化流程--自动播放

    当gameobject setActive(true)的时候自动播放动画 1) 添加DoTween Animation. 设置动画效果, 略 选中 AutoPlay, 取消 AutoKill 2) 在 ...

  7. rpmdeps - 生成 RPM 软件包依赖关系

    SYNOPSIS rpmdeps {-P|--provides} {-R|--requires} FILE ... DESCRIPTION rpmdeps 根据 FILE 参数集合,生成软件包依赖关系 ...

  8. 115-基于TI TMS320DM6467T Camera Link 机器视觉 智能图像分析平台

    基于TI TMS320DM6467无操作系统Camera Link智能图像分析平台 1.板卡概述 该板卡是我公司推出的一款具有超高可靠性.效率最大化.无操作系统的智能视频处理卡,是机器视觉开发上的首选 ...

  9. Fabric管理组件的使用

    Fabric的官方网站: http://www.fabfile.org 帮助文档: https://fabric-chs.readthedocs.io/zh_CN/chs/tutorial.html ...

  10. [数论]原根与指标,BSGS

    刚学了这方面的知识,总结一下.推荐学习数论方面的知识还是看书学习,蒟蒻看的是<初等数论>学的. 这里也推荐几个总结性质的博客,学习大佬的代码和习题. 原根:https://blog.csd ...