Wednesday, 15 May 2013

QTP Script - How to Insert an order in the flight application

In this post, i would like to explain the QTP code along with the necessary documentation while creating the order in the flight application.
Scenario : Created an order by logging into the flight application and click on insert button in the home page by selecting the valid test data .
Note : All the documentation below is highlighted for easiness.
'Option explicit
'Declare the variables
Dim username,password,encpassword,password,dateofflight,FlyFrom,FlyTo,Flight,
Dim Passenger,Radio
'Define the test data - Based on this test data order will be booked
username="testing"
password="mercury"
dateofflight="111113"
FlyFrom="London"
FlyTo="Paris"
Flight="12590"
Passenger="tester"
Radio="1"

'Open the application
InvokeApplication "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe"
'Login
'Verify the login page availability
If  dialog("Login").Exist Then
reporter.ReportEvent micPass,"Login","Login page is availble"
'Agent name field
If  dialog("Login").WinEdit("Agent Name:").Exist Then
'Verify the displayed Label for user name
If dialog("Login").Static("Agent Name:").Exist Then
lbluser=dialog("Login").Static("Agent Name:").GetROProperty("text")
If "Agent Name:"=lbluser Then
reporter.ReportEvent micPass,"Label","Label for username is " & lbluser
else
reporter.ReportEvent micFail,"Label","Label for user name is " & lbluser
End If
End If
dialog("Login").WinEdit("Agent Name:").Set username
reporter.ReportEvent micPass,"Username","Username is availble and the value is set is" & username
else
reporter.ReportEvent micFail,"username","username is not availble"
End If
'Password field
If dialog("Login").WinEdit("Password:").Exist Then
'Verify the displayed Label for user name
lblpass=dialog("Login").Static("Password:").GetROProperty("text")
If "Password:"=lblpass Then
reporter.ReportEvent micPass,"Label","Label for password is "& lblpass
else
reporter.ReportEvent micFail,"Label","Label for password is " & lblpass
End If
               'Encrypt the password by using Crypt method
encpassword=crypt.Encrypt(password)
               'Print the encrypted password in QTP log file
' print encpassword
dialog("Login").WinEdit("Password:").SetSecure encpassword
reporter.ReportEvent micPass,"Password","Password is availble and the value is set is" & encpassword
else
reporter.ReportEvent micFail,"password","password is not availble"
End If
'Ok click
If dialog("Login").WinButton("OK").Exist Then
Dialog("Login").WinButton("OK").Click @@ hightlight id_;_1116162_;_script infofile_;_ZIP::ssf1.xml_;_
reporter.ReportEvent micPass,"OK","Ok is clicked successfully"
else
reporter.ReportEvent micFail,"OK","Ok is not available"
End If
else
reporter.ReportEvent micFail,"Login","Login page is not available"
End If

'Home page

If window("Flight Reservation").Exist Then
'Enter date of flight 
Window("Flight Reservation").ActiveX("MaskEdBox").Type dateofflight 

'Select FlyFrom value
window("Flight Reservation").WinComboBox("Fly From:").Select FlyFrom

'Select FlyTo value
window("Flight Reservation").WinComboBox("Fly To:").Select FlyTo

'Click on flight button
window("Flight Reservation").WinButton("FLIGHT").Click

'Working with Flight list dialog

If window("Flight Reservation").Dialog("Flights Table").Exist Then
listcnt=window("Flight Reservation").Dialog("Flights Table").WinList("From").GetItemsCount
For k=0 to listcnt-1
window("Flight Reservation").Dialog("Flights Table").WinList("From").Select (k)
selrow=window("Flight Reservation").Dialog("Flights Table").WinList("From").GetROProperty("selection")
print selrow
               'Split fucntion is used to separate the values by using a delimiter
arr=split(selrow," ")
If arr(0)=Flight Then
window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
Exit for
End If
Next
End If

'flight number verification

visText=window("Flight Reservation").WinEdit("Flight No:").GetVisibleText
If visText=Flight Then
reporter.ReportEvent micPass,"Displayed flight","Flight displayed as expected and the value is " & visText
else
reporter.ReportEvent micFail,"Displayed flight","Flight displayed as expected and the value is " & visText
End If
' Enter the Passenger name
window("Flight Reservation").WinEdit("Name:").Set Passenger
'Select the radio button class type
'If we have more than two conditions then we have to use SELECT statement
'If we have one or conditions then we will use IF statement
Select Case Radio
Case "1"
Window("Flight Reservation").WinRadioButton("First").Set 
Case "2"
Window("Flight Reservation").WinRadioButton("Business").Set 
Case "3"
window("Flight Reservation").WinRadioButton("Economy").Set
End Select

'Verify the order number before clicking the insert order button

beford=window("Flight Reservation").WinEdit("Order No:").GetVisibleText
If beford<> " " Then
reporter.ReportEvent micFail,"Before order","Before click the insert button the value is " & beford
else
reporter.ReportEvent micPass,"Before order", " before click the insert button the value is " & beford

wait(10)
'Verify the order number after clicking the insert order button

aftInsert=window("Flight Reservation").WinEdit("Order No:").GetROProperty("text")
If not aftInsert = " " Then
reporter.ReportEvent micPass,"before insert","working as expected and the value is" & aftInsert
datatable.Value("OrderNumber",1)=aftInsert
End If
window("Flight Reservation").Close
End If

Note : If user wanted to book a ticket for different destinations then no need to change the script but simply change test data. Hope this will help the QTP guys to start with the scripting.

Just copy paste the code to your test pane and make sure that the required objects are added to the repository before script execution.


No comments:

Post a Comment

Search This Blog

There was an error in this gadget