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

【QTP学习笔记 1 】下拉框数据随机选择,日期输入,如何获取动态的对话框

2013-01-18 16:46 633 查看
最近使用QTP遇到了一些问题,记录一下。

我负责编写的测试脚本流程是这样的:登录mercury自带的定机票页面后,插入一条新记录,插入成功后,再通过order no查询该记录,并传真,核对传真页面上的数据和录入时是否一致。

那需要解决的几个问题的是:

1、机票的日期指定为当前日期的第二天。

2、fly from 和fly to 下拉框随机选择数据。

3、随机选择航班;

4、tickets输入1-10之间的某一位数(该应用是要求订票数<=10)

5、查询出票价和总价格后,要核对总价是否正确(也就是说price*tickets是不是等于total),要考虑去掉$符号才能比较

6、新插入的订单order no是递增上去的,也就是说传真页面的窗口的text值是一直变化的,如果直接通过text取值是取不到这个页面的。

7、要取得fax preview页面上的文本数据。只能取到窗口对象,里面的信息都是文本的,用object spy是获取不到里面的name、price、total、tickets的。

尝试了几次,问题1-6都已经解决,第7点还在考虑。

解决方法如下:

1、日期选择为当前日期的第二天。解决方案:分别取得当前日期的年月日,如果月和日是1位数,则左边补一位0,最后将月&日&年后两位拼装,代码如下。

If len(Month(date+1))=1 Then

 flymon="0"&Month(date+1)

 else

 flymon=Month(date+1)

End If

If Len(Day(date+1))=1 Then

 flyday="0"&Day(date+1)

 else flyday=Day(date+1)

 End If

mydate=flymon&flyday&right(Year(date+1),2)

Window("Flight Reservation").WinObject("Date of Flight:").Type mydate

2、fly from 和fly to 下拉框随机选择数据。解决方案:先取得下拉框之的数量,使用随机函数取得其中一个。

flyfrom_i=Window("Flight Reservation").WinComboBox("Fly From:").GetItemsCount

flyfrom_j=RandomNumber.Value(0,flyfrom_i-1)

Window("Flight Reservation").WinComboBox("Fly From:").Select flyfrom_j

 

flyto_i=Window("Flight Reservation").WinComboBox("Fly To:").GetItemsCount

flyto_j=RandomNumber.Value(0,flyto_i-1)

Window("Flight Reservation").WinComboBox("Fly To:").Select flyto_j

Window("Flight Reservation").WinButton("FLIGHT").Click

3、随机选择航班,解决方案同2

flyspec_i=Window("Flight Reservation").Dialog("Flights Table").WinList("From").GetItemsCount

flyspec_j=RandomNumber.Value(0,flyspec_i-1)

Window("Flight Reservation").Dialog("Flights Table").WinList("From").Select flyspec_j

4、tickets输入1-10之间的某一位数(该应用是要求订票数<=10),解决方案同2

ticks_j=RandomNumber.Value(1,10)

Window("Flight Reservation").WinEdit("Tickets:").Set ticks_j

5、查询出票价和总价格后,要核对总价是否正确(也就是说price*tickets是不是等于total),要考虑去掉$符号才能比较。

解决方案:取price的运行值为“$124.00”,去掉$符号,再运算。total值使用同样的方法

price=Window("Flight Reservation").WinEdit("Price:").GetROProperty("text")

total_fact=mid(Cstr(price),2,len(price)-1)*ticks_j

total_on=Window("Flight Reservation").WinEdit("Total:").GetROProperty("text")

total=mid(Cstr(total_on),2,len(total_on)-1)

If CDbl(total_fact)=CDbl(total) Then

   Reporter.ReportEvent 1,"total calculateion Step", "pass"

   else

   Reporter.ReportEvent 2,"total calculateion Step", "fail"

End If

其中total_fact为实际应得的值,total为界面上得出的值。

6、新插入的订单order no是递增上去的,也就是说传真页面的窗口的text值是一直变化的,如果直接通过text取值是取不到这个页面的。

这个问题是最难的,我考虑了1天,后来想到用描述性编程的方式取得这个窗口。

描述性编程是通过编码虚拟化对象,实际运行时如果页面上对象的属性值和代码里面能够匹配到,就能够识别到这个对象。

Window("Flight Reservation").WinMenu("Menu").Select "File;Open Order..."

Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"

Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set order_num

Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click

Window("Flight Reservation").WinMenu("Menu").Select "File;Fax Order..."

window("text:=Flight reservation").Dialog("Class Name:=Dialog","enabled:=-1").WinObject("attached text:=Fax Number:").Type "1111111111"

window("text:=Flight reservation").Dialog("Class Name:=Dialog","enabled:=-1").WinButton("text:=&Preview Fax").Click

window("text:=Flight reservation").Dialog("Class Name:=Dialog","enabled:=0").Dialog("text:=Fax Preview").Maximize

fax_print=window("text:=Flight reservation").Dialog("Class Name:=Dialog","enabled:=0").Dialog("text:=Fax Preview").GetVisibleText

print fax_print

window("text:=Flight reservation").Dialog("Class Name:=Dialog","enabled:=0").Dialog("text:=Fax Preview").Close

window("text:=Flight reservation").Dialog("Class Name:=Dialog","enabled:=-1").Close

需要注意的是,这里的Fax Preview点击打开后,上级窗口的enable的属性就是0了,就是不可操作的意思。所以我这几行的enable的值是不一样的。

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