Pages

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 variablesDim username,password,encpassword,password,dateofflight,FlyFrom,FlyTo,Flight,Dim Passenger,Radio'Define the test data - Based on this test data order will be bookedusername="testing"password="mercury"dateofflight="111113"FlyFrom="London"FlyTo="Paris"Flight="12590"Passenger="tester"Radio="1"'Open the applicationInvokeApplication "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe"'Login'Verify the login page availabilityIf dialog("Login").Exist Thenreporter.ReportEvent micPass,"Login","Login page is availble"'Agent name fieldIf dialog("Login").WinEdit("Agent Name:").Exist Then'Verify the displayed Label for user nameIf dialog("Login").Static("Agent Name:").Exist Thenlbluser=dialog("Login").Static("Agent Name:").GetROProperty("text")If "Agent Name:"=lbluser Thenreporter.ReportEvent micPass,"Label","Label for username is " & lbluserelsereporter.ReportEvent micFail,"Label","Label for user name is " & lbluserEnd IfEnd Ifdialog("Login").WinEdit("Agent Name:").Set usernamereporter.ReportEvent micPass,"Username","Username is availble and the value is set is" & usernameelsereporter.ReportEvent micFail,"username","username is not availble"End If'Password fieldIf dialog("Login").WinEdit("Password:").Exist Then'Verify the displayed Label for user namelblpass=dialog("Login").Static("Password:").GetROProperty("text")If "Password:"=lblpass Thenreporter.ReportEvent micPass,"Label","Label for password is "& lblpasselsereporter.ReportEvent micFail,"Label","Label for password is " & lblpassEnd If'Encrypt the password by using Crypt methodencpassword=crypt.Encrypt(password) 'Print the encrypted password in QTP log file'print encpassworddialog("Login").WinEdit("Password:").SetSecure encpasswordreporter.ReportEvent micPass,"Password","Password is availble and the value is set is" & encpasswordelsereporter.ReportEvent micFail,"password","password is not availble"End If'Ok clickIf dialog("Login").WinButton("OK").Exist ThenDialog("Login").WinButton("OK").Click @@ hightlight id_;_1116162_;_script infofile_;_ZIP::ssf1.xml_;_reporter.ReportEvent micPass,"OK","Ok is clicked successfully"elsereporter.ReportEvent micFail,"OK","Ok is not available"End Ifelsereporter.ReportEvent micFail,"Login","Login page is not available"End If'Home pageIf window("Flight Reservation").Exist Then'Enter date of flight Window("Flight Reservation").ActiveX("MaskEdBox").Type dateofflight 'Select FlyFrom valuewindow("Flight Reservation").WinComboBox("Fly From:").Select FlyFrom'Select FlyTo valuewindow("Flight Reservation").WinComboBox("Fly To:").Select FlyTo'Click on flight buttonwindow("Flight Reservation").WinButton("FLIGHT").Click'Working with Flight list dialogIf window("Flight Reservation").Dialog("Flights Table").Exist Thenlistcnt=window("Flight Reservation").Dialog("Flights Table").WinList("From").GetItemsCountFor k=0 to listcnt-1window("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 delimiterarr=split(selrow," ")If arr(0)=Flight Thenwindow("Flight Reservation").Dialog("Flights Table").WinButton("OK").ClickExit forEnd IfNextEnd If'flight number verificationvisText=window("Flight Reservation").WinEdit("Flight No:").GetVisibleTextIf visText=Flight Thenreporter.ReportEvent micPass,"Displayed flight","Flight displayed as expected and the value is " & visTextelsereporter.ReportEvent micFail,"Displayed flight","Flight displayed as expected and the value is " & visTextEnd If' Enter the Passenger namewindow("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 statementSelect Case RadioCase "1"Window("Flight Reservation").WinRadioButton("First").Set Case "2"Window("Flight Reservation").WinRadioButton("Business").Set Case "3"window("Flight Reservation").WinRadioButton("Economy").SetEnd Select'Verify the order number before clicking the insert order buttonbeford=window("Flight Reservation").WinEdit("Order No:").GetVisibleTextIf beford<> " " Thenreporter.ReportEvent micFail,"Before order","Before click the insert button the value is " & befordelsereporter.ReportEvent micPass,"Before order", " before click the insert button the value is " & beford

wait(10)'Verify the order number after clicking the insert order buttonaftInsert=window("Flight Reservation").WinEdit("Order No:").GetROProperty("text")If not aftInsert = " " Thenreporter.ReportEvent micPass,"before insert","working as expected and the value is" & aftInsertdatatable.Value("OrderNumber",1)=aftInsertEnd Ifwindow("Flight Reservation").CloseEnd IfNote : 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.