![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
QTP使用技巧
blizzardlyk
这个作者很懒,什么都没留下…
展开
-
QTP中获取当前系统分辨率
<br />利用Description创建对象,分别获取桌面的高度和宽度<br /><br />Public Function get_res()<br />Set progman = Description.Create<br />progman("Object Class").Value = "Progman"<br />progman("Text").Value = "Program Manager"<br />get_res = Window(progman).GetROProperty ("wid原创 2010-08-24 15:37:00 · 834 阅读 · 0 评论 -
QTP通过Winrar或者纯VBS代码压缩指定的文件或文件夹
1,利用QTP中SystemUtil.Run的功能,将指定文件压缩成RAR格式。 代码如下:Function CompressFile(soursefile,targetfile) On error resume next CompressFile = false m1 = chr(34) &targetfile& chr(34) m2 = chr(34) & soursefile原创 2010-08-24 18:37:00 · 1384 阅读 · 0 评论 -
如何改写QTP自带方法来同时操作多个子对象
At times, there are situations where we need to execute the same operation on multiple objects. Example of such situations is listed belowChecking/Unchecking all Check Boxes on a web page Setting转载 2011-01-21 16:14:00 · 1199 阅读 · 0 评论 -
IE的COM对象在注册表中的路径配置
最近遇到一个问题,有同事在机器中装了2个IE浏览器,路径分别是C:\Program Files和C:\Program Files( x86) 结果奇怪的事情发生了。 用 set oIE = CreateObject("InternetExplorer.Application") 方法打开的IE, QTP怎么都识别不了。而在C:\Program Files( x86)下面手动打开的IE,QT原创 2012-12-11 12:35:46 · 2108 阅读 · 0 评论 -
QTP WEB测试中操作IE的一些小技巧
26 Working with MS IE browserConcept: QTP can control an IE window using test object, butalso use IE COM interface. In this chapter we will work on how to work with theIE COM APIs, automation of w转载 2012-09-20 16:32:08 · 5091 阅读 · 0 评论 -
QTP对象的一些隐藏的属性和方法
I’ve been doing some digging into QTP’s test-objects, hoping to find some undocumented methods and techniques. Armed with the power of PDM.DLL, I’ve explored each test object, and have come up with转载 2012-08-23 17:16:00 · 3814 阅读 · 0 评论 -
QTP 结束进程的几种方法
1.Function KillProcess(ProcessName)strComputer = "."Set objWMIService = GetObject("winmgmts://" & strComputer & "/root/cimv2")Set colProcessList = objWMIService.ExecQuery("Select * from Win32_原创 2012-08-15 17:09:28 · 3186 阅读 · 0 评论 -
QTP获取当前测试用例的执行状态
QTP自身的Reporter对象有一个RunStatus属性。那么在每一个用例运行结束时,读取这个属性的值,我们就可以获取当前用例的运行状态。根据运行状态的不同,执行不同的操作。 以下是示例代码:Select Case Reporter.RunStatus Case micFail Call doFailStatusEmail()原创 2011-01-21 15:46:00 · 2501 阅读 · 0 评论 -
QTP 自定义方法将IE最大化最小化
This article demonstrates a quick tip to activate, minimize or maximize browsers. Unlike a Standard Windows Window object, Browser does not support theActivate, Minimize, Maximize methods. Therefo转载 2012-12-03 22:11:11 · 2458 阅读 · 0 评论 -
QTP 更新补丁下载地址
HP官方网站下载补丁需要用户权限。其实直接通过URL就可以访问到相关补丁。 修改补丁编号就可以下载到对应的程序。http://support.openview.hp.com/downloadAPatch.jsp?patchName=QTP_00600.EXE&prodName=qtp&prodRelease=10.0顺便贴个补丁说明列表的链接:ftp://us-ffs.原创 2012-12-03 21:10:26 · 1191 阅读 · 0 评论 -
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,转载 2012-08-23 10:24:56 · 2011 阅读 · 0 评论 -
QTP调用.NET framework类库来实现关于时间的计算和格式转换
通过DotNetFactory来调用.net framework的类库,可以调用一些VBScript所不具备的一些关于时间的计算和格式转换,并且代码量很少。'create new DataTime object by DotNetFactory.CreateInstanceset oDate = DotNetFactory.CreateInstance("System.DateTime").Pa原创 2013-02-18 16:07:26 · 1141 阅读 · 0 评论 -
QTP实现Windows任务栏气泡提示框
当我们的脚本运行时,一切都是在后台默默运行。我们总是希望能够提供一些UI的界面来提示一些脚本的运行状态。而QTP本身只有print 和msgbox 这2个比较普通的基本方法来输出信息,所以我们希望能够找到一些新的方法来强化运行时信息的输出。我们知道,在.Net framework 中,具有很多已经封装好的强大类库,并且QTP可以通过DotNetFactory这个保留对象来创建这些类库中的实例,原创 2013-03-05 21:51:18 · 1626 阅读 · 0 评论 -
QTP使用异步VBS进程并通过系统环境变量传值
在脚本执行过程中,有些程序会启动一些额外的进程来辅助完成一些特殊的功能,例如启动打印机。而某些进程会导致QTP的死锁。因此,我们需要通过一个异步的VBS文件扫描系统进程并结束。另外, 通过创建一个临时的系统环境变量来完成QTP向外部VBS传值。在QTP中的代码如下:'Set a new variable in system environment and start external VB原创 2013-04-26 12:30:09 · 1486 阅读 · 0 评论 -
QTP/UFT 11.5 特性和安装的配置要求
This file provides the following information about UFT 11.51:Getting StartedMinimum System Requirements and Supported EnvironmentsWhat's NewNotes and LimitationsHP Su转载 2013-05-31 13:10:24 · 10843 阅读 · 0 评论 -
用VBS代码实现简单的场景恢复实例
Dim ErrTagErrTag = false Dim RecoveredTagRecoveredTag = falseFunction DemoComponent1 print "Enter component" If not ErrTag Then print "Start recovery" 'call recovery Recovery "DemoCompo原创 2013-08-07 11:17:59 · 1567 阅读 · 0 评论 -
QTP加载第三方DLL实现清除IE缓存
由于QTP的默认编程语言是VBS, 而VBS是一种相对来说功能比较局限的脚本语言,因此我们在编写自动化测试脚本时会有很多功能无法很好的实现。 相对来说c#是一种高级编程语言, 可以实现大多数windows环境下的功能。 所以我们可以借助C#来实现在VBS下无法实现或者实现起来麻烦的功能。 本篇文章以清除IE缓存为例, 介绍QTP如何与.Net framework集成。1, 创建c#原创 2013-12-20 14:41:42 · 2185 阅读 · 0 评论 -
QTP调用win32 API 实现窗口的最小最大化
调用win32 API 实现窗口的最小最大化,特别应用在IE窗口操作上,可以有效的释放占用内存。Public Function min_and_max(hwnd) Extern.Declare micVoid ,"SendMessageA","user32.dll","SendMessageA",micHwnd,micInteger,micInteger,micInt转载 2011-08-03 15:48:35 · 2496 阅读 · 0 评论 -
用AOM对象模式实现QTP的远程调用
随着测试团队的不断增大,测试脚本的数量也日渐增多。相信很多有自动化项目经验的人都体会过,使用单个机器去运行所有脚本,会导致整个测试过程冗长而缺乏稳定性。而且,很多自动化测试的要求是一套脚本,多环境运行。当遇到项目所提供的测试周期经常,用例数量大,测试环境多这样的问题时,分步试运行就变得尤为重要。 像Load Runner一样,我们需要一个Controler来发布测试命令,驱动其他Gen原创 2011-01-24 10:25:00 · 2925 阅读 · 1 评论 -
IntelliSense for your Custom QTP Class in 6 Steps
by Anshoo Arora on June 30, 2011 I have been using classes in my frameworks for a long time now, and my biggest gripe about QTP is its lack of Intellisense for custom classes. It also happens转载 2012-12-03 21:50:32 · 1106 阅读 · 0 评论 -
QTP,在代码中调用Setting中的Parameter
<br />在QTP,setting中,可以添加Parameter,通过QTP的保留对象TestArgs,可以访问到这些参数的值。<br /> <br /> <br />示例代码:<br />msgbox TestArgs("UserName")转载 2010-08-24 16:37:00 · 1323 阅读 · 0 评论 -
QTP中使用DotNetFactory转换图片格式
<br />QTP可以通过DotNetFactory.CreateInstance 来创建.NET自带的类库实例并使用其方法。<br />以下示例代码展示,如何.ne t中的System.Drawing命名空间中的类来转换图片格式。'Convert image from one format to the another formatPublic Function ConvertImage(ByVal fromFile, ByVal toFile) Dim oImageLib ' as Syste翻译 2010-08-24 16:45:00 · 1128 阅读 · 0 评论 -
QTP运行时,动态加载外部共享对象库
<br />QTP使用外部共享对象库有2种方法。<br />1,通过菜单Resources -> Associate Repositories,关联外部对象库到指定的Action。<br /> <br />2,通过RepositoriesCollection对象,在运行时灵活的加载,自动关联到当前Action。加载外部对象库 执行脚本移除加载的对象库<br />'Upload object repository <br />RepositoriesCollection.Add "../test.tsr"<b原创 2010-08-25 09:57:00 · 3361 阅读 · 0 评论 -
QTP中判断Action运行是否超时
<br />1,需要在环境变量中自定义一个最大超时时间<br />Environment("MAX_ACTION_TIMEOUT")<br /> <br />2,判断是否超时的方法:<br />Dim INT_ACTION_STARTTIME_MSEC 'global variable<br />INT_ACTION_STARTTIME_MSEC = Timer 'start time<br /><br />Public Function CheckIfActionReachedTimeout()<br /原创 2010-08-24 14:58:00 · 1332 阅读 · 1 评论 -
在QTP中实现语音功能
<br />我们可以通过调用Excel的API来实现系统自动语音功能。<br />示例代码:<br />Set excel = CreateObject( "Excel.Application" )<br />excel.Speech.Speak "Advanced QTP"<br />Set excel = nothing翻译 2010-08-24 15:06:00 · 851 阅读 · 2 评论 -
调用Windows的API,在QTP中实现高亮对象的方法
<br />在QTP的帮助文档中,展示了如何调用Windows自身的API来实现更灵活的操作。<br /> <br />以下的方法实现在屏幕上高亮一个矩形区域,来突出被测对象的位置。' Declare necessary APIs Extern.Declare micHwnd, "GetDesktopWindow", "User32.DLL", "GetDesktopWindow" Extern.Declare micULong, "GetWindowDC", "User32.DLL", "翻译 2010-08-25 11:29:00 · 2109 阅读 · 0 评论 -
QTP,在描述性编程中使用Run-time属性来定义对象
<br />How to identify Web objects through their Runtime Attributes.<br /><br />Set ImgDesc = Description.CreateImgDesc("attribute/nodeName").Value ="IMG"ImgDesc("attribute/nameProp").Value = "minimize/.gif"ImgDesc("attribute/cs").Value = "Minimize" <翻译 2010-08-24 15:59:00 · 830 阅读 · 0 评论 -
QTP连接QC时,通过QCUtil对象获取QC中的Test信息
<br /> <br />最近几天,开始尝试QTP与QC的连接操作。<br />写了几个方法,来获取QTP脚本在QC中所在的不同目录的路径信息。<br />GetCurrentTestSet: 返回当前脚本所在的Test Set的路径名称<br />GetCurrentInstance:返回当前脚本在Test Set中的步骤名称及运行时的实例名称<br />GetCurrentTestName:返回当前脚本在Test Plan中的绝对路径<br /> <br /> <br />Function GetCur原创 2010-08-24 17:40:00 · 2638 阅读 · 0 评论 -
QTP中,通过WScript.Shell对象,实现自动弹出并自动关闭的Msgbox
本内容摘自QTP自身的帮助文档。Using Message Boxes That Close Automatically <br /><br />The function below shows a message box that disappears after the specified timeout (in seconds). The script execution then continues. <br /><br />Public Sub MsgBoxTimeout (Text, Title翻译 2010-08-25 10:32:00 · 3430 阅读 · 0 评论 -
QTP中,两种获取剪贴板内容的方法
当在我们在使用QTP过程中,可能会遇到不可识别的对象,但是又需要获取对象中的文字信息。遇到这种情况,可以先用sendkey的方法通过Ctrl+c的方式获取到剪贴板中,然后通过创建 HTMLFILE对象来获取剪切板中的内容。代码如下:Set ie = CreateObject("htmlfile")ClipboardText = ie.ParentWindow.ClipboardData.GetData("text")print ClipboardText原创 2010-09-02 10:03:00 · 2010 阅读 · 0 评论 -
QTP,以数据库的形式访问Excel
<br />通常,我们与Excel的交互,是通过创建Excel对象的方式:<br />Set ExcelApp = CreateObject("Excel.Application") <br /> <br />但是在需要处理格式规范、数据量大的数据表的时候,不妨采取数据库的操作方式,使得操作更高效、灵活。<br />把Excel表格的第一行作为字段名,其余行作为数据项。<br /> <br />范例代码:<br />'创建连接字符串<br />Function ConnetString(FilePath)<原创 2010-09-01 10:25:00 · 943 阅读 · 0 评论 -
将QTP运行时的错误截图上传到QC测试集中
<br /> 如果在测试运行时,将每一步的截图都上传至QC,那么将大量耗费QC的系统资源。通常,我们只想查看那些发生错误时的截图。当调试和运行失败后,需要查找原因时,这些截图可以迅速帮助定位问题。<br /> 通过下述步骤,可以很简单的实现上述需求。在公共函数库中创建一个类,并此类的一个实例在类的析构函数中判断是否发生错误并截图将截图作为附件上传到QC中当前测试集的实例中。<br />以下是这个类的完整代码:' Class: QCImageErrorCapture' WebSite:翻译 2011-01-21 14:46:00 · 2450 阅读 · 0 评论 -
增强QTP中Debug View的功能
增强QTP Debug View的实践。1,通过安装VS2008或者仅注册PDM.DLL(9.0.30729.1),可以增强QTP的Debug功能,在Debug View中,看到对象更多的属性或者方法.Copy文件到"c:/Program Files/Common Files/Microsoft Shared/VS7DEBUG" 并注册.在开始菜单中点击RUN 并输入以下内容:RegS原创 2010-08-30 16:48:00 · 2157 阅读 · 1 评论 -
通过QTP的XMLUTIL将XML和字典对象Dictionary之间的互相转换
本文转自knowledgeInbox 在QTP运行过程中,如果中途出现意外情况,导致运行停止。那么,内存中关于当前CASE的状态信息就会丢失。因此,需要一个中转信息的媒介,来保存运行时必要的信息,以供后续运行时继续读取。笔者认为,XML是个一个很好的数据储存载体。因此,写了以下2个方法,来分别展示Dictionary对象与XML之间数据的存储和读取。'Function: Load翻译 2011-01-21 14:15:00 · 1729 阅读 · 0 评论 -
QTP创建WScript.Shell对象执行DOS命令行并获取返回值
Dim wShell, execSet wShell = CreateObject( "WScript.Shell" )Set exec = wShell.Exec ("ipconfig /all") print exec.StdOut.ReadAll print exec.StdErr.ReadAllwait(5)原创 2010-09-07 16:57:00 · 3170 阅读 · 0 评论 -
QTP关闭除了ALM/QC以外的所有IE窗口
1:function Close_IE_Except_ALMSet obj = CreateObject("Shell.Application")Set obj1 = obj.WindowsFor Each objIE in obj1 If objIE.name = "Windows Internet Explorer" Then If Not Instr(Ucas原创 2010-09-07 13:52:00 · 1642 阅读 · 0 评论 -
通过C# 添加站点到IE信任列表
1, DLL 部分实现:2, QTP/UFT中调用:原创 2014-11-19 16:22:06 · 1822 阅读 · 0 评论