您的位置:首页 > 编程语言 > Qt开发

qtp一个比较综合的使用[功能]

2009-10-19 17:40 489 查看
1.启动一个VB的windows application。设置好Excel文件和QTP的安装路径。
2.启动脚本进行测试,测试代码是QTP自带的订票系统。

[脚本的参数设定]
脚本中有2个参数-EXCEL文件和QTP安装路径从VBS文件传入。在QTP中设定如下:
1.在KeyWord view界面。在Action1上点击右键,选Action properties,弹出 Action properties对话框。在其中添加2个入参。如下图所示:



2.设置测试参数
Test->Test Settings->Parameters.设置2个入参。如下图所示:



3.将Action参数和Test参数关联起来
1.在KeyWord view界面。在Action1上点击右键,选择Action Call properties



点Vaiue







在脚本中使用以下语句可以取得2个入参:
filename= Parameter("InAction1")
QtpPath= Parameter("InAction2")
[脚本部分]
Dim conn,rst,filename,coboname
Dim user,passwd
'filename="C:/DATA.xls"
filename= Parameter("InAction1")
QtpPath= Parameter("InAction2")
'datatale.import(filename)
Set conn= createobject("ADODB.Connection")
'msgbox filename
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source="&filename&";Extended Properties='Excel 8.0;hdr=yes'"
Set rst= createobject("ADODB.Recordset")

' Excelファイルのデータを読み込む
rst.Open "select * from [sheet1$] " ,conn,1,1

' table WHCT0717のデータをセットする
While Not rst.EOF
systemutil.run QtpPath&"/samples/flight/app/flight4a.exe",""
user = rst.fields("user")
passwd = rst.fields("password")
Dialog("ログイン").WinEdit("代理店名:").Set (user)
' Dialog("ログイン").WinEdit("代理店名:").Type micTab
Dialog("ログイン").WinEdit("パスワード:").set(passwd)
Dialog("ログイン").WinButton("OK").Click
reporter.filter=0
If ( Dialog("ログイン").Dialog("フライト予約").WinButton("OK").Exist(2) ) Then
text = Dialog("ログイン").Dialog("フライト予約").GetVisibleText
reporter.ReportEvent micFail ,"Load Error",text
Dialog("ログイン").Dialog("フライト予約").WinButton("OK").Click
Dialog("ログイン").WinButton("キャンセル").Click
else
Window("フライト予約").close
end if
rst.MoveNext
Wend
rst.close

脚本部分最主要的是注意QTP对象的选择和使用。(Tools-->object Repository 对象的添加和删除)

[VB application]
以下是Button1单击的触发事件
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim qtApp
Dim qtTest
Dim qtResultsOpt
Dim pDefColl, pDef, rtParams, rtParam1, rtParam2
Dim QtpTestPath
qtApp = CreateObject("QuickTest.Application")
qtApp.Launch()
qtApp.Visible = True '使得QTP的程序可见

' 设置运行属性
QtpTestPath = QtpPath.Text & "/Tests/Test3" '设置脚本路径
qtApp.Options.Run.RunMode = "Fast"
qtApp.Open(QtpTestPath, True) ' Open the test in read-only mode

' set run settings for the test
qtTest = qtApp.Test
qtTest.Settings.Run.OnError = "NextStep"
qtResultsOpt = CreateObject("QuickTest.RunResultsOptions")
qtResultsOpt.ResultsLocation = "D:/program files/Mercury Interactive/QuickTest Professional/Tests/Test3" ' 设置放结果的地方

pDefColl = qtApp.Test.ParameterDefinitions
Dim cnt = pDefColl.Count
Dim Indx = 1
While Indx <= cnt
pDef = pDefColl.Item(Indx)
Indx = Indx + 1
End While
rtParams = pDefColl.GetParameters()
rtParam1 = rtParams.Item("InParameter1")
rtParam1.Value = DataFileName.Text
' MsgBox(TextBox1.Text)
rtParam2 = rtParams.Item("InParameter2")
rtParam2.Value = QtpPath.Text

qtTest.Run(, True, rtParams) ' Run the test
'MsgBox(rtParams.Item("OutParameter1").Value)

'qtTest.Close ' Close the test
qtResultsOpt = Nothing ' Release the Run Results Options object
qtTest = Nothing ' Release the Test object
qtApp = Nothing ' Release the Application object
qtTest.quit()

End Sub
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐