Thursday, May 22, 2008

QTP Recovery Scenario 2


1)
This is an example of Object State trigger event.

Open QTP and Flight Reservation window.
Click Record in QTP in order to start recording.
Enter Date of Flight, Fly From, Fly To fields.
Click Flights... button. Flights Table opens. Click OK.
Enter Name and Click Insert Order.
After Insert Order is complete the Delete icon is enabled.

Now our Recovery scenario works if this delete icon is disabled (when its enabled property is False)

SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").WinEdit("Agent Name:").Set "sach"
Dialog("Login").WinEdit("Agent Name:").Type micTab
Dialog("Login").WinEdit("Password:").SetSecure "484190f7c6928cfbf4630e91eaf4d2901b3381e1"
Dialog("Login").WinEdit("Password:").Type micReturn
Window("Flight Reservation").WinObject("Date of Flight:").Type "090909"
Window("Flight Reservation").WinComboBox("Fly From:").Select "Denver"
Window("Flight Reservation").WinComboBox("Fly To:").Select "Frankfurt"
Window("Flight Reservation").WinButton("FLIGHT").Click
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
Window("Flight Reservation").WinEdit("Name:").Set "sach"
Window("Flight Reservation").WinButton("Insert Order").Click
Window("Flight Reservation").WinButton("Button_2").Click
Window("Flight Reservation").Dialog("Flight Reservations").WinButton("No").Click
Window("Flight Reservation").WinMenu("Menu").Select "File;Exit"

2)
Go to File->New->Function Library
A new Function Library will be open. Without writing anything in the Function Library (let it be empty), just Save it and close it.
We will create Recovery Function in accordance with the prototype syntax of the Pop-up window at the time of creating a Recovery Scenario.

3)
Go to Resources->Recovery Scenario Manager...
Recovery Scenario Manager window opens
Click on "New Scenario" icon to open Recovery Scenario Wizard.
Click Next.
From Select Trigger Event, choose Object State. Click Next.
In Select Object area, click on hand and then click on the Delete icon on the Flight Reservation window.
Click OK in "Object Selection - Object State Trigger" window. Click Next.
Set Object properties and Values window opens. Click Add/Remove..button
In the Edit Properties window, check only window id and enabled and click OK.
Edit the enabled property to False. Click Next
Again click Next in Recovery Operations area.
Choose Recovery Operation as Function Call, click next.
On the next screen, click on button on the right of "Function Library" dropdown to select the function library we created earlier.
Click "Define new function:" radio button and The function in the Function prototype will be:

Function RecoveryFunction1(Object)
msgbox "hello Function"
End Function

Click Next
In the Recovery Operation window uncheck "Add another recovery operation". Click Next.
In the Post-Recovery Test Run Options choose "Stop the test run" radio button. Click Next.
Give the Recovery Scenario a Name and Description and click Next
In the Completing the Recovery Scenario Wizard area check "Add scenario to current test" and click Finish.
In the Recovery Scenario Manager window you will see one scenario added in the scenarios area.
Click Close and save the Recovery Scenario.

Make sure you do not forget to associate Function Library (While in Function Library, go to File menu, there you will see the option of association it to Test) to a Test.

To see the recovery scenario working, try to run the test with lines 6 to 12 of the code in section 1 (line which types date to the line which clicks Insert Order button) commented.