[不定时更新] QTP常用代码段

最近软件自动化测试,正在学习QTP,即 IBM公司的 QuickTest Professional.这篇文章专门作为收集一些常用的代码段使用。

 

 

一、Action间参数传递
1.调用Action本身的参数

Parameter(“faxnum”)

 

2.获取Action的输出参数

RecordNo = Parameter(“OpenOrder_Action”,”RecordNo”)
‘获取OpenOrder_Action的输出参数RecordNo

 

3. 将参数和DataTable传入要调用的Action中

RunAction “FaxOrder_Action”, oneIteration, DataTable(“faxnum”, dtGlobalSheet),RecordNo

 

 

二、打开文件的常用方法
在QTP中,常需要利用QTP的代码来打开某些程序或文件,下面提供三种常用的方法:

 

1、SystemUtil.Run ‘ SystemUtil对象的Run方法

SystemUtil.Run “D:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe”

 

2、InvokeApplication ‘ 调用程序函数

InvokeApplication “D:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe”

 

3、WSH ‘ 通过wsh对象的Run(bat)或者exec(exe)方法

Dim oWSH
Set oWSH = CreateObject(“WScript.shell”)
oWSH.exec “D:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe”
Set oWSH = nothing

Dim oWSH
Set oWSH = CreateObject(“WScript.shell”)
oWSH.run “ E:\WORK\Projects\3.bat”
Set oWSH = nothing
 

结合ERR对象和on err resume next语句所做的例子:

On Error Resume Next
Dim bFlag
bFlag = CBool(bFlag)
bFlag =systemutil.Run (“C:\WINDOWS\system32\calc.exe”)
MsgBox bFlag
If Err.Number<>0 Then
MsgBox Err.Description
Err.Clear
End If