录制该实例时,出现过很多问题,里面有个很奇怪问题“Cannot find the "Agent name must be at least 4 characters long." object's parent "Login" (class Dialog).Verify that parent properties match an object currently displayed in your application.”,一直认为是不识别对象,又是改语句的,又是增加虚拟对象,都没一个成功,最后才查出是代码问题,少判断了"Flight Reservations"是否存在情况?导致跑到正确登录时候出问题。
最终代码如下:
'应用QTP自带订票系统
'应用六个不同登录情况测试用例
'检验弹出提出信息是否正确
Dim i
Dim istatus'预期值变量
Dim outvalue '实际值变量
For i=1 to datatable.GetSheet("Action1").getrowcount '循环从1到Action1最后一行
Dialog("Login").WinEdit("Agent Name:").Set DataTable("username", dtLocalSheet)
Dialog("Login").WinEdit("Password:").SetSecure DataTable("password", dtLocalSheet)
Dialog("Login").WinButton("OK").Click
If Dialog("Login").Dialog("Flight Reservations").Exist Then
'插入输出检查点,参数化outmsg
Dialog("Login").Dialog("Flight Reservations").Static("Agent name must be at least 4 characters long.").Output CheckPoint("Agent name must be at least 4 characters long.")
istatus=datatable("status",dtlocalSheet) '将预期值status赋予变量istatus
outvalue=datatable("outmsg",dtlocalSheet) '将实际值outmsg赋予变量outvalue
If istatus <> outvalue Then
reporter.ReportEvent 1,"登录功能测试","预期值为"+istatus+",实际值为"+outvalue
else
reporter.ReportEvent 0,"登录功能测试","登录成功!"
End If
Dialog("Login").Dialog("Flight Reservations").WinButton("确定").Click
else
Window("Flight Reservation").Close
End If
datatable.getsheet("Action1").setnextrow '获取Action1下一行数据
Next
如果觉得《软件功能测试订票系统 QTP自动化测试自带订票系统登录功能》对你有帮助,请点赞、收藏,并留下你的观点哦!