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 on ADODB 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




  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
quicktest professional 12.5简称QTP,这是一款专业的软件自动化测试工具,绝对是测试人员的法宝,它为开发人员和测试人员提供了实用的功能,可以方便开发者对软件的漏洞进 行测试和修复,软件集成了软件测试一体化流程,只需要将要测试的应用导入,便可以进行相应的分析了. 主要功能: 1)QTP是一个侧重于功能的回归自动化测试工具;提供了很多插件,如:.NET的,Java的,SAP的,Terminal Emulator的等等,分别用于各自类型的产品测试。默认提供Web,ActiveX和VB。 2)QTP支持的脚本语言是VB,这对于测试人员来说,感觉要“舒服”得多(如相比SilkTest采用C语言)。VB毕竟是一种松散的、非严格的、普及面很广的语言。 3)QTP支持录制和回放的功能。录制产生的脚本,可以拿来作为自己编写脚本的template。录制时,还支持一种lower level 功能,这个对于QTP不容易识别出来的对象有用,不过它是使用坐标来标识的,对于坐标位置频繁变动的对象,采用这种方式不可行。另外,QTP的编辑器支持两种视图:Keyword模式和Expert模式。Keyword模式想法是好的,提供一个描述近似于原始测试用例的、跟代码无关的视图(我基本很少用,除了查看、管理当前test中各个action的完整流程),而Expert就是代码视图,一般编写脚本都在这个区域。 4)一个有用的工具:ObjectSpy,可以用来查看Run-time object和Test object属性和方法。 5)QTP通过三类属性来识别对象:a)Mandatory; b)Assitive; c)Ordinalidentifiers。大部分情况下,通过对象的一些特定属性值就可以识别对象(类型a)。这些属性可以通过Tools->Object Identification 定义。 6)Object Repository(OR)是QTP存储对象的地方。测试脚本运行后,QTP根据测试脚本代码,从这个对象库中查找相应对象。每个Action可以对应有一个或者多个OR,也可以设置某个OR为 sharable的,这样可以供其他Action使用。注意,使用QTP录制功能时,默认将被测对象放在local OR中,可以通过 Resources->Object Respository,选择Local查看。 7)说到QTP的要点,不得不说Action。Action是QTP组织测试用例的具体形式,拥有自己的DataTable和Object Repository,支持Input和output参数。Action可以设置为share类型的,这样可以被其他test中的Action调用(注意:QTP是不支持在一个test中调用另外一个test的,只有通过sharable action来调用)。 8)如3)所述,一个test中,多个action的流程组织,只有通过Keyword视图查看和删除,在Expert视图中没有办法看到。 9)调用Action可以通过菜单Insert->Callto *** 来实现。QTP提供三种类型的调用方式:a)call to new Action,在当前test中创建一个新的Action;b)call to Copy of Action;c)call to existing action,调用一个re-usable action,如果这个re-usableaction来自另外一个test,将以只读的方式插入到当前test中。 10)QTP提供excel 形式的数据表格DataTable,可以用来存放测试数据或参数。DataTable有两种类型:global 和local。QTP为DataTable提供了许多方法供存取数据,在对测试代码进行参数化的时候,这些方法非常有用。 11)环境变量(EnvironmentVariables)。在一个test中,环境变量可以被当前test中所有action共享。环境变量也有两种类型:build in 和user defined。用户自定义的环境变量可以指向一个XML文件,这样可以实现在众多test之间共享变量。 12)QTP可以引用外部的VBS代码库,通过Settings-》Resource加入,也可以ExecuteFile命令在代码中直接执行。这种VBS库可以为所有action和test共享。 13)QTP默认为每个test提供一个测试结果,包括Passed,Failed,Done,Warning和information几种状态类型,可以进行对结果Filter。但是,只能为每个test产生一个testing result,不能为多个testing产生一个总的testing res
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值