实验二 功能测试与 QTP 测试工具(4 学时)
1 实验目的
(1)理解和掌握自动化测试的基本原理和方法。
(2)掌握 QTP 标准检查点的设置方法。
(3)掌握 QTP 动态捕捉信息与循环脚本的设计的方法。
2 实验要求
(1)使用 QTP 对订票程序的 Insert order 功能进行测试,验证订票是否成功。
(2)掌握在 QTP 中检查点的添加方法。
(3)使用 QTP 对被测程序 AUT 进行动态信息捕捉的操作。
(4)掌握对测试脚本中取出多个值进行循环脚本的设计。
3 实验内容
(1)录制并生成订票脚本,按照三种方式来添加检查点,通过对 update order 按钮、delete
order 按钮、Insert Done 按钮和 Order No:文本框的属性进行验证,来判断订票是否成功;
(2)在订票脚本的基础上,通过设计循环脚本,动态取出“出发地”和“目的地”的
所有航班,同时动态选择当前出发地与目的地之间的某一个航班,并测试程序是否正确。
4 实验步骤
(1)录制脚本:成功登陆订票窗口→在订票系统中输入航班日期→选择起飞地点→选
择目的地→选择航班→输入顾客姓名→输入票的张数→选择航班级别→单击订票按钮;其
中,用户名为姓名全拼,密码为学号
(2)在日期栏输入 当前日期,选择起始和目的地点:Denver 和 Frankfurt,选择航班
号 15819,确定订单中的航班,输入订票姓名”姓名全拼”,订票张数是 2 张,航班选择 first,
确定当前订票信息,单击”insert order”按钮。
(3)脚本录制完成后,脚本及订单图如下所示:
Dialog("Login").WinEdit("Agent Name:").Set "姓名全拼"
Dialog("Login").WinEdit("Password:").SetSecure
"4f669b9da99a7e76169a9134e948b20c8a2f4edc"
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").WinMenu("Menu").Select "File;New Order"
Window("Flight Reservation").ActiveX("MaskEdBox").Type "当前日期"
Window("Flight Reservation").WinComboBox("Fly From:").Select "Denver"
Window("Flight Reservation").WinComboBox("Fly To:").Select "Frankfurt"
Window("Flight Reservation").WinButton("FLIGHT").Click
Window("Flight Reservation").Dialog("Flights Table").WinList("From").Select
DEN
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
Window("Flight Reservation").WinEdit("Name:").Set "zhangsan"
03:12 PM FRA
03:57 PM AA
$104.10"
"15889
1
Window("Flight Reservation").WinEdit("Tickets:").Set "2"
Window("Flight Reservation").WinRadioButton("First").Set
Window("Flight Reservation").WinButton("Insert Order").Click
(4)回访脚本,检查脚本的正确性;
(5)在 Active Screen 中,用右键单击”Update Order”按钮,添加标准检查点,检查”Update
Order”按钮的 enabled 属性值。如下图所示:
(6)点击 OK 按钮,打开 checkpoint 设置窗口,选择 enabled 属性,在 Configure Value
中,选择 Constant,输入 enabled 属性的预期值为 True,选”After current step”,点击“OK”,
如下图所示:
2
(7)增加完检查点后,脚本在 keyword 视图下,如下图所示:
(8)脚本在 expert view 下,如下所示:
Dialog("Login").WinEdit("Agent Name:").Set "test"
Dialog("Login").WinEdit("Password:").SetSecure
"4f669b9da99a7e76169a9134e948b20c8a2f4edc"
3
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").WinMenu("Menu").Select "File;New Order"
Window("Flight Reservation").ActiveX("MaskEdBox").Type "当前日期"
Window("Flight Reservation").WinComboBox("Fly From:").Select "Denver"
Window("Flight Reservation").WinComboBox("Fly To:").Select "Frankfurt"
Window("Flight Reservation").WinButton("FLIGHT").Click
Window("Flight Reservation").Dialog("Flights Table").WinList("From").Select
DEN
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
Window("Flight Reservation").WinEdit("Name:").Set "zhangsan"
Window("Flight Reservation").WinEdit("Tickets:").Set "2"
Window("Flight Reservation").WinRadioButton("First").Set
Window("Flight Reservation").WinButton("Insert Order").Click
Window("Flight Reservation").WinButton("Update Order").Check CheckPoint("Update
Order")
03:12 PM FRA
"15889
03:57 PM AA
$104.10"
(9)回放脚本,查看检查点的检查结果,测试报告是否显示为 passed;
(10)在 expert view 下,将鼠标放置到 checkpoint(“update order”)上,右键点击鼠标,
选择 checkpoint properties,再次打开检查点属性设置窗口,选择 enabled 属性,在 Configure
Value 中,选择 Constant,输入 enabled 属性的预期值为 False,如下图所示:
(11)重新回访脚本,查看此时的测试报告是否为 Failed,并检查是否有出错的截图。
(12)对 delete order 按钮和 Insert Done 按钮按照以上的步骤,设置标准检查点,验证
enabled 属性是否为正确的值;
对 delete order 按钮当 enable 属性设置为 false 时,结果如下所示:
当对 delete order 按钮当 enable 属性设置为 true 时,结果如下所示:
对 Insert Done 按钮当 enable 属性设置为 true 时,结果如下所示:
对 Insert Done 按钮当 enable 属性设置为 false 时,结果如下所示:
(13)循环脚本实现完备测试:
附录一:循环脚本参考
Int_FlyFrom=Window("Flight Reservation").WinComboBox("Fly From:").GetItemsCount
For i=0 to Int_FlyFrom-1
Str_FlyFrom = Window("Flight Reservation").WinComboBox("Fly From:").GetItem(i)
4
Window("Flight Reservation").WinComboBox("Fly From:").Select Str_FlyFrom
Int_FlyTo = Window("Flight Reservation").WinComboBox("Fly To:").GetItemsCount
For j=0 to Int_FlyTo-1
Str_FlyTo = Window("Flight Reservation").WinComboBox("Fly To:").GetItem(j)
Window("Flight Reservation").WinComboBox("Fly To:").Select Str_FlyTo
Window("Flight Reservation").WinButton("FLIGHT").Click
Int_Flight
Window("Flight
=
Reservation").Dialog("Flights
Table").WinList("From").GetItemsCount
For k=0 to Int_Flight-1
If k>0 Then
Window("Flight Reservation").WinMenu("Menu").Select "File;New Order"
Window("FlightReservation").ActiveX("MaskEdBox").Type "121212"
Window("Flight Reservation").WinComboBox("Fly From:").Select Str_FlyFrom
Window("Flight Reservation").WinComboBox("Fly To:").Select Str_FlyTo
Window("Flight Reservation").WinButton("FLIGHT").Click
Int_Flight=Window("FlightReservation").Dialog("Flights
Table").WinList("From").GetItemsCount
For k=0 to Int_Flight-1
Str_Flight
=
Table").WinList("From").GetItem(k)
Window("Flight
Reservation").Dialog("Flights
Window("FlightReservation").Dialog("Flights Table").WinList("From").Select Str_Flight
Window("FlightReservation").Dialog("Flights Table").WinButton("OK").Click
Next
Next
Next
5