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 ' 關閉這個窗口
 
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章