QTP学习笔记(四)

今天把我测试的flight的脚本放上来,请大家一起研究指点。
 
action1:登录界面
 
systemutil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"  ' 启动flight程序
Dialog("Login").Static("Static").Check CheckPoint("Static")  ' 检查login的飞机那张图片
Dialog("Login").Check CheckPoint("Login")  ' 检查login登录框的login字符是否存在
Dialog("Login").WinEdit("Agent Name:").Set "Croshere"  ' 输入名字
Dialog("Login").WinEdit("Password:").SetSecure "4933a785bad34ecea7ebc8dfb0012103bd022fc5"  ' 输入密码
Dialog("Login").WinButton("Cancel").Check CheckPoint("Cancel")  ' 检查cancel按钮
Dialog("Login").WinButton("Help").Check CheckPoint("Help")  ' 检查help按钮
Dialog("Login").WinButton("OK").Click  ' 点击ok按钮
 
action2:订票界面
 
' 以下这段是生成随机日期,日期是在2008年12月1日到2038年12月31日之间。
'且输入格式为MM/DD/YY,而YY是取最后两位数。
'因为输入到对话框格式原因,如:8月要写成08,
'而因为datatable的原因,第一位数字为0时会省略,估要在0前加'号,才不会省略0。
'因为此日期无法用函数方法生成,估只能在6位数中每位数生成随机数再合并起来。
Dim sMonth,sMonth1,sMonth2,sDay,sDay1,sDay2,sYear,sYear2,TkerData 
Randomize
sYear1=Int(4*Rnd)
If sYear1=0  Then
 sYear2=int(8+2*rnd)
elseif sYear1=3 then
 sYear2=int(9*rnd)
else
 sYear2=int(10*rnd)
End If
sYear=sYear1 & sYear2
If sYear=08  Then
 sMonth=12
else
 sMonth1=int(2*rnd)
 If sMonth1=1  Then
  sMonth2=int(3*rnd)
 else
  sMonth2=int(1+9*rnd)
 End If
 sMonth=sMonth1 & sMonth2
End If
If sMonth=01 Then
 sDay1=int(4*rnd)
 If sDay1=3 Then
  sDay2=int(2*rnd)
 else
  sDay2=int(1+9*rnd)
 End If
 elseif sMonth=03 then
  sDay1=int(4*rnd)
 If sDay1=3 Then
  sDay2=int(2*rnd)
 else
  sDay2=int(1+9*rnd)
 End If
elseif sMonth=05 then
  sDay1=int(4*rnd)
 If sDay1=3 Then
  sDay2=int(2*rnd)
 else
  sDay2=int(1+9*rnd)
 End If
elseif sMonth=07 then
  sDay1=int(4*rnd)
 If sDay1=3 Then
  sDay2=int(2*rnd)
 else
  sDay2=int(1+9*rnd)
 End If 
elseif sMonth=08 then
  sDay1=int(4*rnd)
 If sDay1=3 Then
  sDay2=int(2*rnd)
 else
  sDay2=int(1+9*rnd)
 End If
elseif sMonth=10 then
  sDay1=int(4*rnd)
 If sDay1=3 Then
  sDay2=int(2*rnd)
 else
  sDay2=int(1+9*rnd)
 End If
elseif sMonth=12 then
  sDay1=int(4*rnd)
 If sDay1=3 Then
  sDay2=int(2*rnd)
 else
  sDay2=int(1+9*rnd)
 End If
elseif sMonth=02 then
 sDay1=int(3*rnd)
 If (sYear mod 4)=0 Then
  sDay2=int(1+9*rnd)
 else
  If sDay1=2 Then
   sDay2=int(1+8*rnd)
  else
   sDay2=int(1+9*rnd)
  End If
 End If
elseif sMonth=04 then
 sDay1=int(4*rnd)
 If sDay1=3  Then
  sDay2=0
 else
  sDay2=int(1+9*rnd)
 End If
elseif sMonth=06 then
 sDay1=int(4*rnd)
 If sDay1=3  Then
  sDay2=0
 else
  sDay2=int(1+9*rnd)
 End If
elseif sMonth=09 then
 sDay1=int(4*rnd)
 If sDay1=3  Then
  sDay2=0
 else
  sDay2=int(1+9*rnd)
 End If
elseif sMonth=11 then
 sDay1=int(4*rnd)
 If sDay1=3  Then
  sDay2=0
 else
  sDay2=int(1+9*rnd)
 End If
End If
sDay=sDay1 & sDay2
If sMonth1=0 Then
 sMonth1=chr(39) & sMonth1
 sMonth=sMonth1&sMonth2
End If
If sMonth=Chr(39) Then
 sMonth=12
End if
TkerData=sMonth & sDay & sYear  ''到此生成随机日期TkerData
DataTable("Data_Of_Flight",dtGlobatSheet)=TkerData '把随机日期值赋予给列 Data_Of_Flight
window("Flight Reservation").ActiveX("MaskEdBox").Type DataTable("Data_Of_Flight",dtGlobatSheet) '读取列Data_Of_Flight的随机日期,输入到Date of Flight框上
 
Randomize
Dim counts,temp1,temp2,aa
counts=window("Flight Reservation").WinComboBox("Fly From:").GetItemsCount '得到FLY FROM里的选项总数值赋给counts
temp1=int(rnd*counts) '对counts进行随机,得出来得数赋给变量temp1
window("Flight Reservation").WinComboBox("Fly From:").Select(temp1) '选择变量temp1的数值所在的项
counts=window("Flight Reservation").WinComboBox("Fly To:").GetItemsCount '得到FLY TO里的选项总数值赋给counts
temp2=int(rnd*counts)  '对counts进行随机,得出来得数赋给变量temp2
Do while temp2=temp1 '当temp1的值等于temp2时
 temp2=int(rnd*counts) '对counts进行随机,得出来得数赋给变量temp2
Loop '如果不等就结束循环
window("Flight Reservation").WinComboBox("Fly To:").Select(temp2) ''选择变量temp1的数值所在的项

window("Flight Reservation").WinButton("FLIGHT").Click '点击按钮Flight
aa=window("Flight Reservation").WinComboBox("Fly From:").GetROProperty("text") '用GetROProperty来得到当前WinComboBox的text赋给aa
DataTable("Fly_From",dtGlobatSheet)=aa 'aa赋给列Fly_From
aa=window("Flight Reservation").WinComboBox("Fly To:").GetROProperty("text") '用GetROProperty来得到当前WinComboBox的text赋给aa
DataTable("Fly_To",dtGlobatSheet)=aa 'aa赋给列Fly_To
 
itemcounts=window("Flight Reservation").Dialog("Flights Table").WinList("From").GetItemsCount '把winlist里面的总数赋给itemcounts
selectcount=randomnumber(0,itemcounts) '随机选择0到itemcounts总数的值赋给selectcount
window("Flight Reservation").Dialog("Flights Table").WinList("From").Select(selectcount) '选择selectcount值所在的选项
window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click '点击OK
 
aa=window("Flight Reservation").WinEdit("Flight No:").GetROProperty("text") '用GetROProperty来得到当前winedit的text赋给aa
DataTable("Flight_No",dtGlobatSheet)=aa 'aa赋给列Flight_No
aa=window("Flight Reservation").WinEdit("Departure Time:").GetROProperty("text") '用GetROProperty来得到当前winedit的text赋给aa
DataTable("Departure_Time",dtGlobalSheet)=aa 'aa赋给列Departure_Time
aa=window("Flight Reservation").WinEdit("Arrival Time:").GetROProperty("text") '用GetROProperty来得到当前winedit的text赋给aa
DataTable("Arrival_Time",dtGlobatSheet)=aa 'aa赋给列Arrival_Time
aa=window("Flight Reservation").WinEdit("Airline:").GetROProperty("text") '用GetROProperty来得到当前winedit的text赋给aa
DataTable("Airline",dtGlobatSheet)=aa 'aa赋给列Airline
 
Dim RndNameLth,j,k,RndStr
RndNameLth=int(3+6*Rnd) '定义随机名字的长度至少为3个字符到8个
For i = 1 To RndNameLth
j = 97+Int(26*Rnd)  'acsii字符,97为a,97+25=122为z
k=chr(j) '数字转为字母
RndStr =RndStr&k
next
TkerName=RndStr
window("Flight Reservation").WinEdit("Name:").Set TkerName '对name输入随机名(TkerNum)

aa=window("Flight Reservation").WinEdit("Name:").GetROProperty("text") '用GetROProperty来得到当前winedit的text赋给aa
DataTable("name",dtGlobalSheet)=aa  'aa赋给列name
 
Dim TkerNum
TkerNum=int(1+9*rnd)
window("Flight Reservation").WinEdit("Tickets:").Set TkerNum '对tickets输入随机数(TkerNum)
DataTable("Tickets",dtGlobatSheet)=TkerNum '把随机数赋给列Tickets
 
aa=window("Flight Reservation").WinEdit("Price:").GetROProperty("text") '用GetROProperty来得到当前winedit的text赋给aa
DataTable("Price",dtGlobalSheet)=aa 'aa赋给列Price
aa=window("Flight Reservation").WinEdit("Total:").GetROProperty("text") '用GetROProperty来得到当前winedit的text赋给aa
DataTable("Total",dtGlobalSheet)=aa 'aa赋给列Total
 
Set des=description.Create() '创建description对象
des("Class Name").value="WinRadioButton" '为description对象添加描述属性
Set radioBtn=window("Flight Reservation").ChildObjects(des) '用ChildObjects来获取父对象下的des子对象
index=randomnumber(0,2) '随机从0到2选一个数
radioBtn(index).click '点击随机数的按钮

DataTable("Class",dtGlobatSheet)=radioBtn(index).GetROProperty("text") '用GetROProperty来得到当前winedit的text赋给列Class
window("Flight Reservation").WinButton("Insert Order").Click '点击insert Order
 
wait 10 '等待10秒
 
aa=window("Flight Reservation").WinEdit("Order No:").GetROProperty("text") '用GetROProperty来得到当前winedit的text赋给aa
DataTable("Order_No",dtGlobatSheet)=aa 'aa赋给列Order_No
 
DataTable.Export "c:\1.xls"  ' 输出DataTable到c盘1.xls
 
window("Flight Reservation").Close  ' 关闭这个窗口
 
 

你可能感兴趣的:(职场,qtp,休闲)