写了几天的脚本,也算是对qtp的vb入门了。。。
Option Explicit
'Declaretion and Initialization
Dim intItemCount
Dim intRdmSelect
Dim strTotalPrice
Dim intTimeCount
Dim intOrderNo
intTimeCount=DataTable("TimeCount",dtGlobalSheet)
'========================================================
' In order to get a changeable date and satisfy the special format
Dim strCurrentDate,strMyDate,strLastDate,strType
strCurrentDate=date 'get the current date
strMyDate=split(strCurrentDate,"/",-1,1) 'Intercept the date string to an array
strType=strMyDate(2) mod 400 'setup an temporary Parameter to Distinguish the Leap year
strMyDate(2)=mid(strMyDate(2),3,2) 'return two characters from the strMyDate(2)
strMyDate(1)=strMyDate(1)+1 'set up a new day
Select Case strMyDate(0)
Case "2"
Select Case strType
'Distinguish the Leap year
Case "0"
Select Case strMyDate(1)
Case "30"
strMyDate(0)=strMyDate(0)+1 'set up a new month
strMyDate(1)=1
End Select
'if it's February and not a leap year,then it has 28 days
Case else
Select Case strMyDate(1)
Case "29"
strMyDate(0)=strMyDate(0)+1
strMyDate(1)=1
End Select
End Select
'Distinguish the month which has 31 days
Case "1" or "3" or "5" or "7" or"8" or"10"
Select Case strMyDate(1)
Case "32"
strMyDate(0)=strMyDate(0)+1
strMyDate(1)=1
End Select
'Distinguish the month which has only 30 days
Case "4" or "6" or "9" or "11"
Select Case strMyDate(1)
Case "31"
strMyDate(0)=strMyDate(0)+1
strMyDate(1)=1
End Select
'if it's the last day of December, set up to the next year
Case "12"
Select Case strMyDate(1)
Case "32"
strMyDate(2)=strMyDate(2)+1
strMyDate(1)=1
strMyDate(0)=1
End Select
End Select
If (strMyDate(0)<10 and strMyDate(1)<10) Then
strLastDate="0"&strMyDate(0)&"0"&strMyDate(1)&strMyDate(2)
elseif (strMyDate(0)<10 and strMyDate(1)>=10) then
strLastDate="0"&strMyDate(0)&strMyDate(1)&strMyDate(2)
elseif(strMyDate(0)>=10 and strMyDate(1)<10 ) then
strLastDate=strMyDate(0)&"0"&strMyDate(1)&strMyDate(2)
elseif(strMyDate(0)>=10 and strMyDate(1)>=10) then
strLastDate=strMyDate(0)&strMyDate(1)&strMyDate(2)
End If
'===============================================================
Window("Flight Reservation").WinMenu("Menu").Select "File;New Order"
Window("Flight Reservation").ActiveX("MaskEdBox").Type strLastDate
Window("Flight Reservation").WinComboBox("Fly From:").Select DataTable("fly_from", dtLocalSheet)
Window("Flight Reservation").WinComboBox("Fly To:").Select DataTable("fly_to", dtLocalSheet)
Window("Flight Reservation").WinButton("FLIGHT").Click
'get the number of the select items
intItemCount=Window("Flight Reservation").Dialog("Flights Table").WinList("From").GetROProperty("items count")
Randomize
'get the random number to select
intRdmSelect=RandomNumber(0, intItemCount-1)
Window("Flight Reservation").Dialog("Flights Table").WinList("From").Select (intRdmSelect)
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
Window("Flight Reservation").WinEdit("Name:").Set "test"&RandomNumber(1, 100)
Window("Flight Reservation").WinRadioButton("First").SetToProperty "text","Business"
Window("Flight Reservation").WinRadioButton("First").Set
Window("Flight Reservation").WinEdit("Tickets:").Set RandomNumber(1, 10)
'Verify the relation between the price and total price
strTotalPrice=window("Flight Reservation").WinEdit("Price:").GetROProperty("text")* window("Flight Reservation").WinEdit("Tickets:").GetROProperty("text")
strTotalPrice=FormatCurrency(strTotalPrice,2,-1,-1,0)
If strTotalPrice=window("Flight Reservation").WinEdit("Total:").GetROProperty("text") then
Reporter.ReportEvent micPass,"Verify" ,"tickets total price is right. And the price is "&strTotalPrice
Else
reporter.ReportEvent micFail,"Verify" ,"tickets total price is wrong,the expected price is"&strTotalPrice &" and the actual price is"&window("Flight Reservation").WinEdit("Total:").GetROProperty("text")
end if
Window("Flight Reservation").WinButton("Insert Order").Click
' loop until the “Insert Done…” text in the status bar
Do
intTimeCount=intTimeCount+1
wait 1
If intTimeCount>60 Then
Exit do
End If
Loop until Window("Flight Reservation").ActiveX("Threed Panel Control").GetROProperty("text")="Insert Done..."
'
'Verify the orderNo
intOrderNo=Window("Flight Reservation").WinEdit("Order No:").GetROProperty("text")
If intOrderNo<>0 Then
Reporter.ReportEvent micPass,"Verify" ,"order tickets successfully with Order No is"& intOrderNo
else
Reporter.ReportEvent micFai,"Verify" ,"order tickets failed,the order number is null"
Call Exittest
End If
DataTable("OrderNo",dtGlobalSheet)=intOrderNo 'put the intOrderNo to the global sheet