练习1:Flight4a
要求:
a.录制Flight4a登录+购票+退出业务流程
b.实现登录1次,购票3次,退出1次
c.对Fly From、Fly to、航班实现随机参数化
随机参数化:RandomNumber
控件:Fly From
总数:items count
获取运行时的值:GetRoProperty("属性名")
Test13001_Flight4a_for循环购票
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\HP\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").WinEdit("Agent Name:").Set "Jack"
Dialog("Login").WinEdit("Password:").SetSecure "5a653b3a0f6bbea696af1a25046189d3d3608901"
Dialog("Login").WinButton("OK").Click
wait 6
'开始购票
For i=1 to 3
Window("Flight Reservation").WinButton("Button").Click
Window("Flight Reservation").ActiveX("MaskEdBox").Type "111119"
' FromCount保存起飞城市的总数
Dim FromCount
FromCount=Window("Flight Reservation").WinComboBox("Fly From:").GetROProperty("items count")
Window("Flight Reservation").WinComboBox("Fly From:").Select RandomNumber(0,FromCount-1)
' ToCount保存到达城市的总数
Dim ToCount
ToCount=Window("Flight Reservation").WinComboBox("Fly To:").GetROProperty("items count")
Window("Flight Reservation").WinComboBox("Fly To:").Select RandomNumber(0,ToCount-1)
Window("Flight Reservation").WinButton("FLIGHT").Click
' FlyCount保存航班的总数
Dim FlyCount
FlyCount=Window("Flight Reservation").Dialog("Flights Table").WinList("From").GetROProperty("items count")
Window("Flight Reservation").Dialog("Flights Table").WinList("From").Select RandomNumber(0,FlyCount-1)
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
Window("Flight Reservation").WinEdit("Name:").Set "Jack"
Window("Flight Reservation").WinButton("Insert Order").Click
wait 6
'结束购票
Next
Window("Flight Reservation").Close
练习2:Flight4a
要求:
a.录制Flight4a登录+购票+退出业务流程
b.对购票时输入的Tickets实现随机参数化
c.使用自定义检查点检查票数*单价=总价
reporter.ReportEvent micPass,"",""
reporter.ReportEvent micFail,"",""
Test13002_Flight4a_自定义检查票价
Option Explicit '强制检查语法
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\HP\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").WinEdit("Agent Name:").Set "Jack"
Dialog("Login").WinEdit("Password:").SetSecure "5a654f4183d15630c35108a1e6230bd4bcbde035"
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").ActiveX("MaskEdBox").Type "111119"
Window("Flight Reservation").WinComboBox("Fly From:").Select "Frankfurt"
Window("Flight Reservation").WinComboBox("Fly To:").Select "Denver"
Window("Flight Reservation").WinButton("FLIGHT").Click
Window("Flight Reservation").Dialog("Flights Table").WinList("From").Select "20178 FRA 12:48 PM DEN 01:33 PM SR $162.80"
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
Window("Flight Reservation").WinEdit("Name:").Set "Jack"
'1、随机生成1到10的数字,输入Tickets时使用
Dim Tickets
Tickets=Cint(RandomNumber(1,10))
'2、把代码中输入的Tickets替换为随机生成的数字
Window("Flight Reservation").WinEdit("Tickets:").Set Tickets
'3、获取Price的值 $100.10
Dim Price
Price=Window("Flight Reservation").WinEdit("Price:").GetROProperty("text")
'4、获取Total的值 $100.20
Dim Total
Total=Window("Flight Reservation").WinEdit("Total:").GetROProperty("text")
'5、 去掉$符号,转换为double子类型
Price=Cdbl(mid(Price,2))
Total=Cdbl(mid(Total,2))
'6、判断Tickets*Price=Total
If abs(Tickets*Price-Total)<0.01 Then
Reporter.ReportEvent micPass,"检查票价","票数*票价=总价,票数是:"&Tickets&",票价是:"&Price&",总价是:"&Total
else
' 给失败的界面截图
Dim pic
pic="D:\检查票价.png"
desktop.CaptureBitmap pic,True
'desktop.CaptureBitmap "路径",True
' True表示截图存在,就覆盖,False就不覆盖
Reporter.ReportEvent micFail,"检查票价","票数*票价=总价,票数是:"&Tickets&",票价是:"&Price&",总价是:"&Total,pic
End If
Window("Flight Reservation").WinButton("Insert Order").Click
Window("Flight Reservation").Close
补充:如何判断浮点数是否相等
abs(浮点数1-浮点数2)<精度
abs:取绝对值
精度:自己定义
Tickets=Cint(RandomNumber(1,10))
"票数*票价=总价,票数是:"&Tickets&",票价是:"&Price&",总价是:"&Total
Reporter.ReportEvent micPass
Reporter.ReportEvent micFail
Reporter.ReportEvent micPass,"步骤名称","成功",pic
"票数*票价=总价,票数是:"&Tickets&",票价是:"&Price&",总价是:"&Total&""
练习3:Flight4a
要求:
a.录制Flight4a登录+购票+打开订单+退出业务流程
b.把购票生成的订单号获取,打开订单时使用
c.使用自定义检查点验证打开的订单是否为购票生成的订单
Test13003_Flight4a_自定义检查打开订单
Option Explicit
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\HP\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").WinEdit("Agent Name:").Set "Jack"
Dialog("Login").WinEdit("Password:").SetSecure "5a6580d62c2a67817dc9888c1e89d3529f4cf0c7"
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").ActiveX("MaskEdBox").Type "111119"
Window("Flight Reservation").WinComboBox("Fly From:").Select "Frankfurt"
Window("Flight Reservation").WinComboBox("Fly To:").Select "Paris"
Window("Flight Reservation").WinButton("FLIGHT").Click
Window("Flight Reservation").Dialog("Flights Table").WinList("From").Select "12670 FRA 09:34 AM PAR 11:29 AM AF $175.60"
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
Window("Flight Reservation").WinEdit("Name:").Set "Jack"
Window("Flight Reservation").WinButton("Insert Order").Click
wait 6
'1、获取购票生成的订单号
Dim No
No=Window("Flight Reservation").WinEdit("Order No:").GetROProperty("text")
Window("Flight Reservation").WinButton("Button").Click
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"
'2、打开订单时使用购票生成的订单号
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set No
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click
'3、获取打开订单后的订单号
Dim afterNo
afterNo=Window("Flight Reservation").WinEdit("Order No:").GetROProperty("text")
'4、判断打开的订单号是否与购票生成的订单号一致
If afterNo=No Then
Reporter.ReportEvent micPass,"验证订单号","一致"
else
Dim pic
pic="D:\验证订单号.png"
desktop.CaptureBitmap pic,True
Reporter.ReportEvent micFail,"验证订单号","不一致",pic
End If
Window("Flight Reservation").Close
练习4:Flight4a
要求:
a.录制Flight4a登录+打开不存在的订单+退出业务流程
b.打开订单实现随机参数化,500-1000
c.使用自定义检查点,验证打开不存在订单时的提示信息中是否包含输入的订单号
d.使用for循环打开5次订单
Test13004_Flight4a_自定义检查提示信息
Option Explicit
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\HP\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").WinEdit("Agent Name:").Set "Jack"
Dialog("Login").WinEdit("Password:").SetSecure "5a658eb213d5d0a5a9c2b75936eb475fa60b4d08"
Dialog("Login").WinButton("OK").Click
Dim i
For i=1 to 5
Window("Flight Reservation").WinButton("Button").Click
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"
'1、获取500-1000之间的随机数
Dim orderNo
orderNo=RandomNumber(500,1000)
'2、把打开订单输入的订单号替换为随机数
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set orderNo
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click
'3、点击OK按钮打开订单号后,获取提示信息内容
Dim info
info=Window("Flight Reservation").Dialog("Open Order").Dialog("Flight Reservations").Static("Order number 500 does not exist").GetROProperty("text")
'4、判断info是否包含orderNo
If instr(info,orderNo)<>0 Then
Reporter.ReportEvent micPass,"判断提示信息","提示信息包含订单号"
else
Reporter.ReportEvent micFail,"判断提示信息","提示信息不包含订单号"
End If
Window("Flight Reservation").Dialog("Open Order").Dialog("Flight Reservations").WinButton("确定").Click
Window("Flight Reservation").Dialog("Open Order").WinButton("Cancel").Click
Next
Window("Flight Reservation").Close
一、Exist属性)
1、Exist属性时动态属性,记录被测系统控件对象是否出现\存在于被测系统中
2、Exist属性值:
True:代表存在\出现
False:代表不存在\未出现\消失
项目老师在不在
If 项目经理.Exist Than
叫他过来
else
不叫
3、应用场景:
a.页面跳转(从A页面跳转到B页面),需要检查B页面的控件对象是否出现
b.检查某个对象控件是否出现
c.检查某个对象控件消失
练习5:Flight4a
要求:
a.录制Flight4a登录+退出业务流程
b.使用Exist属性验证登录是否成功
Test13005_Flight4a_Exist属性验证登录
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\HP\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").WinEdit("Agent Name:").Set "Jack"
Dialog("Login").WinEdit("Password:").SetSecure "5a65978beafbf13bba1cf5d969e498d6e4ec59b6"
Dialog("Login").WinButton("OK").Click
'1、验证登录是否成功,
'只要Flight Reservation窗口对象存在,就表示登录成功
'如果不存在,就表示登录失败
If Window("Flight Reservation").Exist(8) Then
Reporter.ReportEvent micPass,"验证登录是否成功","成功!"
else
Reporter.ReportEvent micFail,"验证登录是否成功","失败!"
End If
Window("Flight Reservation").Close
练习6:Flight4a
要求:
a.录制Flight4a系统打开后关闭系统
b.验证登录对话框已经被关闭
Test13006_Flight4a_Exist登录消失
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\HP\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").WinButton("Cancel").Click
'1、判断Login对话框不存在
If Not Dialog("Login").Exist(3) Then
msgbox "登录框不存在"
else
msgbox "登录框存在"
End If
'1+1=2
'判断1+1等于2 要判断 等于
'If 1+1=2 Then
' 等于
'else
' 不等于
'End If
'
'
'判断1+1不等3 要判断 不等于
'If 1+1 !=3 Then
' 不等于
'else
' 等于
'End If
4、Exist属性用自定义检查点中的语法:
(1)检查对象存在:
if 对象.Exist(秒数) Then
记录成功
else
记录失败
End if
(2)检查对象消失,不存在
if Not 对象.Exist(秒数) Then
记录成功
else
记录不成功
End if
5、注意:Exist属性QTP封装的每个控件对象的动态属性,可以直接使用对象.Exist获取属性的值,值是True或者False,不需要使用GetRoProperty
练习7:Flight4a系统
要求:
a.判断Flight Reservation窗口对象是否存在
如果存在就关闭
如果不存在,就判断Login对话框是否存在
如果存在,就输入用户名、密码登录系统,关闭系统
如果不存在,就打开被测系统,关闭被测系统
Window("Flight Reservation")
练习8:Flight4a
要求:
a.录制时在登录界面,不输入任何信息,点击OK按钮
b.使用自定义检查点验证提示信息框对象是否存在
c.如果b步骤的提示框对象存在,使用文本检查点检查提示框中提示的信息内容是否正确,点击确认按钮,关闭提示框,验证提示框是否消失
Test13007_Flight4a_Exist验证登录提示信息
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\HP\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").WinButton("OK").Click
'1、判断Dialog("Flight Reservations")是否存在
If Dialog("Login").Dialog("Flight Reservations").Exist(3)Then
' 存在
Dialog("Login").Dialog("Flight Reservations").Static("Please enter agent name").Check CheckPoint("Please enter agent name")
Dialog("Login").Dialog("Flight Reservations").WinButton("确定").Click
' 2、判断信息提示框是否消失
If Not Dialog("Login").Dialog("Flight Reservations").Exist(3) Then
Reporter.ReportEvent micPass,"验证提示框","关闭"
else
Reporter.ReportEvent micFail,"验证提示框","未关闭"
End If
else
' 不存在
Reporter.ReportEvent micFail,"验证提示框","未打开"
End If
Dialog("Login").WinButton("Cancel").Click