关于飞机订票系统的脚本分享
最近研究了一段时间的qtp,一直拿mercury的flight41.exe和一个订票的网站,做实验,小要有成果!拿出来和大家分享一下!此贴对于高手是没有必要看的,因为没什么内涵和技术含量。但是对于像我这样的新手,这点脚本的东西还是琢磨了好一段时间了,希望能给大家的学习一点点的帮助!
#################################
' 新建一条订票信息
'飞行日期参数化
'#################################
Window("Flight Reservation").Restore
Window("Flight Reservation").WinButton("Button").Click
Window("Flight Reservation").WinObject("Date of Flight:").Type DataTable("Date_of_Flight", dtGlobalSheet)
'######################################
' 出发地点随机选择下拉列表中的一项
'######################################
Dim n1,Rdm_flyfrom
n1=Window("Flight Reservation").WinComboBox("Fly From:").GetROProperty("items count")
Randomize
Rdm_flyfrom=RandomNumber(0,n1-1)
'msgbox(Rdm_flyfrom)
Window("Flight Reservation").WinComboBox("Fly From:").Select (Rdm_flyfrom)
wait(2)
'######################################
' 目的地点随机选择下拉列表中的一项
'######################################
Dim n2,Rdm_flyto
n2=Window("Flight Reservation").WinComboBox("Fly To:").GetROProperty("items count")
Randomize
Rdm_flyto=RandomNumber(0,n2-1)
'msgbox(Rdm_flyto)
Window("Flight Reservation").WinComboBox("Fly To:").Select (Rdm_flyto)
wait(2)
'############################################################################
' 点击Flights按钮;随即选择一个时间点的航班:点击OK按钮;旅客姓名参数化
'###################################### #####################################
Window("Flight Reservation").WinButton("FLIGHT").Click
Window("Flight Reservation").Dialog("Flights Table").WinList("From").Select RandomNumber(0, 100)
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
Window("Flight Reservation").WinEdit("Name:").Set DataTable("Name", dtGlobalSheet)
'Radioitems=Window("Flight Reservation").WinRadioButton("Business").GetROProperty("Button")
'msgbox(Button)
'############################################################################################
'手工产生一个随机数,达到随机选择商务舱、经济舱、头等舱的目的,点击Insert Order插入订票信息
'############################################################################################
'方法(一)
'Dim x1,x2
'Randomize
'x1=RandomNumber(1,3)
' If x1="1" then
' x2="Business"
'else if x1="2" then
' x2="Economy"
' else x2="First "
' end if
' end if
'Window("Flight Reservation").WinRadioButton(x2).Set
'方法(二)
Dim i,b
i=RandomNumber(1,3)
Select Case i
Case 1 b="First"
Case 2 b="Business"
Case 3 b="Economy"
End Select
Window("Flight Reservation").WinRadioButton("First").SetTOProperty"text",b
Window("Flight Reservation").WinRadioButton("First").Set
Window("Flight Reservation").WinButton("Insert Order").Click
wait(6)
Dim RecordNo,Radioitems '定义一个变量
RecordNo=Window("Flight Reservation").WinEdit("Order No:").GetROProperty("text") '获取Order No
DataTable("OrderNo",dtGlobalSheet)=RecordNo '将OrderNo写入datatable,以后检查用
'#######################
'订票详细信息的获取
'#######################
Dim flyfrom,flyto,flightno,departuretime,arrivaltime,airline,price,total
flyfrom=Window("Flight Reservation").WinComboBox("Fly From:").GetROProperty("regexpwndtitle")
flyto=Window("Flight Reservation").WinComboBox("Fly To:").GetROProperty("regexpwndtitle")
flightno=Window("Flight Reservation").WinEdit("Flight No:").GetROProperty("regexpwndtitle")
departuretime=Window("Flight Reservation").WinEdit("Departure Time:").GetROProperty("regexpwndtitle")
arrivaltime=Window("Flight Reservation").WinEdit("Arrival Time:").GetROProperty("regexpwndtitle")
airline=Window("Flight Reservation").WinEdit("Airline:").GetROProperty("regexpwndtitle")
price=Window("Flight Reservation").WinEdit("Price:").GetROProperty("regexpwndtitle")
total=Window("Flight Reservation").WinEdit("Total:").GetROProperty("regexpwndtitle")
'#########################################################
'将订票的详细信息插入到datatable中,作为run-time datatable
'#########################################################
DataTable("flyfrom",dtGlobalSheet)=flyfrom
DataTable("flyto",dtGlobalSheet)=flyto
DataTable("flightno",dtGlobalSheet)=flightno
DataTable("departuretime",dtGlobalSheet)=departuretime
DataTable("arrivaltime",dtGlobalSheet)=arrivaltime
DataTable("airline",dtGlobalSheet)=airline
DataTable("price",dtGlobalSheet)=price
DataTable("total",dtGlobalSheet)=total
[ 本帖最后由 liweilovend 于 2009-10-13 15:22 编辑 ] '###########################################
'检查点【一】,根据CustomerName进行检查。
'###########################################
Window("Flight Reservation").WinButton("Button_2").Click ' 点击打开按钮
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Customer Name").Set "ON" ' 勾选Customer Name
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set DataTable("Name", dtGlobalSheet) ' 输入Datatable中的旅客姓名
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click ' 点击OK进行查找
Dim countx ' 定义一个变量
countx=Window("Flight Reservation").Dialog("Open Order").Dialog("Search Results").WinList("Flight No.").GetROProperty("items count")
' 改变量可以获取最新的动态查询结果的个数
Window("Flight Reservation").Dialog("Open Order").Dialog("Search Results").WinList("Flight No.").Select (countx) '在查找出来的结果中选择第一项
Window("Flight Reservation").Dialog("Open Order").Dialog("Search Results").WinButton("OK").Click '点击OK按钮
Window("Flight Reservation").WinObject("Date of Flight:").Check CheckPoint("Date of Flight:") ' 增加飞行日期的检查点
Window("Flight Reservation").WinComboBox("Fly From:").Check CheckPoint("FlyFrom:") ' 增加出发地点的检查点
Window("Flight Reservation").WinComboBox("Fly To:").Check CheckPoint("FlyTo:") ' 增加目的地的检查点
Window("Flight Reservation").WinEdit("Name:").Check CheckPoint("Name:") '增加旅客姓名检查点
Window("Flight Reservation").WinEdit("Order No:").Check CheckPoint("Order No:") '增加order no检查点
Window("Flight Reservation").WinEdit("Flight No:").Check CheckPoint("Flight No:") '增加FlightNo检查点
Window("Flight Reservation").WinEdit("Departure Time:").Check CheckPoint("Departure Time:") '增加Departure Time检查点
Window("Flight Reservation").WinEdit("Arrival Time:").Check CheckPoint("Arrival Time:") '增加Arrival Time检查点
Window("Flight Reservation").WinEdit("Airline:").Check CheckPoint("Airline:") '增加Airline 检查点
Window("Flight Reservation").WinEdit("Price:").Check CheckPoint("Price:") '增加Price检查点
Window("Flight Reservation").WinEdit("Total:").Check CheckPoint("Total:") '增加Total检查点
'###########################################
'检查点【二】,根据Order No.进行检查。
'###########################################
Window("Flight Reservation").WinButton("Button_2").Click '点击打开按钮
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON" '勾选Order No.
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit_2").Set (RecordNo) '根据获取到的RecordNo查询订票信息
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click ' 点击OK进行查找
Window("Flight Reservation").WinObject("Date of Flight:").Check CheckPoint("Date of Flight:") ' 增加飞行日期的检查点
Window("Flight Reservation").WinComboBox("Fly From:").Check CheckPoint("FlyFrom:") ' 增加出发地点的检查点
Window("Flight Reservation").WinComboBox("Fly To:").Check CheckPoint("FlyTo:") ' 增加目的地的检查点
Window("Flight Reservation").WinEdit("Name:").Check CheckPoint("Name:") ' 增加旅客姓名检查点
Window("Flight Reservation").WinEdit("Order No:").Check CheckPoint("Order No:") '增加order no检查点
Window("Flight Reservation").WinEdit("Flight No:").Check CheckPoint("Flight No:") '增加FlightNo检查点
Window("Flight Reservation").WinEdit("Departure Time:").Check CheckPoint("Departure Time:") '增加Departure Time检查点
Window("Flight Reservation").WinEdit("Arrival Time:").Check CheckPoint("Arrival Time:") '增加Arrival Time检查点
Window("Flight Reservation").WinEdit("Airline:").Check CheckPoint("Airline:") '增加Airline 检查点
Window("Flight Reservation").WinEdit("Price:").Check CheckPoint("Price:") '增加Price检查点
Window("Flight Reservation").WinEdit("Total:").Check CheckPoint("Total:") '增加Total检查点 '###########################################
'检查【三】,根据Flight Date.进行检查。
'###########################################
Window("Flight Reservation").WinButton("Button_2").Click '点击打开按钮
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Flight Date").Set "ON" '勾选Order No.
Window("Flight Reservation").Dialog("Open Order").WinObject("__/__/__").Click 2,8 '点击输入Flight的日期输入框
Window("Flight Reservation").Dialog("Open Order").WinObject("__/__/__").Type DataTable("Date_of_Flight", dtGlobalSheet)'将datatable中的data_of_flight写入
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click '点击确定按钮进行查询
Dim county '定义一个变量
county=Window("Flight Reservation").Dialog("Open Order").Dialog("Search Results").WinList("Flight No.").GetROProperty("items count")
'改变量可以获取最新的动态查询结果的个数
Window("Flight Reservation").Dialog("Open Order").Dialog("Search Results").WinList("Flight No.").Select (county) '因为查询结果按照order no从小到大排列,所以最新插入的order最大排在最后边
Window("Flight Reservation").Dialog("Open Order").Dialog("Search Results").WinButton("OK").Click '点击OK按钮
Window("Flight Reservation").WinObject("Date of Flight:").Check CheckPoint("Date of Flight:") ' 增加飞行日期的检查点
Window("Flight Reservation").WinComboBox("Fly From:").Check CheckPoint("FlyFrom:") ' 增加出发地点的检查点
Window("Flight Reservation").WinComboBox("Fly To:").Check CheckPoint("FlyTo:") ' 增加目的地的检查点
Window("Flight Reservation").WinEdit("Name:").Check CheckPoint("Name:") ' 增加旅客姓名检查点
Window("Flight Reservation").WinEdit("Order No:").Check CheckPoint("Order No:") '增加order no检查点
Window("Flight Reservation").WinEdit("Flight No:").Check CheckPoint("Flight No:") '增加FlightNo检查点
Window("Flight Reservation").WinEdit("Departure Time:").Check CheckPoint("Departure Time:") '增加Departure Time检查点
Window("Flight Reservation").WinEdit("Arrival Time:").Check CheckPoint("Arrival Time:") '增加Arrival Time检查点
Window("Flight Reservation").WinEdit("Airline:").Check CheckPoint("Airline:") '增加Airline 检查点
Window("Flight Reservation").WinEdit("Price:").Check CheckPoint("Price:") '增加Price检查点
Window("Flight Reservation").WinEdit("Total:").Check CheckPoint("Total:") '增加Total检查点
'###########################################
'删除该订票记录
'###########################################
Window("Flight Reservation").WinButton("Delete Order").Click
Window("Flight Reservation").Dialog("Flight Reservations").WinButton("是(Y)").Click 谢谢分享 谢谢分享,对我来说,我这个都还没研究出来。。。 不过我看这个还是迷迷糊糊的,,,呵呵。。。 多谢楼主共享代码
如果取(0-100)的随机数,大部分概率会选到最后一个航班:)
回复 7# 的帖子
可改用VBS的Rnd函数 Window("Flight Reservation").WinObject("Date of Flight:").Type DataTable("Date_of_Flight", dtGlobalSheet)为什么我的winobject qtp识别不了呢?? :loveliness:建议去看看QTP官方自带的例子 我也看看 谢谢楼主分享! 感谢楼主 DataTable("flyfrom",dtGlobalSheet)=flyfrom这个地方是怎么定义的,怎么调用的,怎么识别的,新手啊,,谁回答下,多谢! 楼主好人,谢分享 qtp中的那几个检查点为什么是灰色不可操作?
请告诉下 谢谢
页:
[1]