Execution of automated test cases might result in some unexpected error conditions. In such situations, QTPs error handling feature Recovery Scenario comes in handy.
To create a Recovery Scenario, we need to configure the below steps:
- Trigger Event
- Recovery Operation
- Post-Recovery Test Run Options
- Name and Description of the Recovery Scenario
- Finish
Click Resources –> Recovery Scenario Manager
Click on the New Recovery Scenario icon
Click Next button on Recovery Scenario Wizard
Select the Trigger Event
Following are the different Trigger Events available:
- Pop-up window
- Object state
- Test run error
- Application crash
We will discuss only one trigger event in this post:
Pop-up window
After performing certain operation, sometime we might expect a popup window. If the popup window is blocking the execution QTP throws “Object is disabled” Run error. This is because QTP is not able to identify the object in the next step. Hence, to overcome this situation we can use Recovery Scenario.
To demonstrate the above situation, we will record “Update order” scenario in Flight application.
- Open the flight application
- Enter valid username / password
- Open the record with a date 12/12/12 (This record has to be created earlier with Insert order scenario)
- Edit the date once the record is opened (just try to delete 12 and then re-enter the same)
- Click update order
- It throws the error
- Without clicking the OK button on the error popup QTP will throw “Object disabled error”
- Here we need a recovery scenario
Create a Recovery Scenario as below:
- As explained above, get the error popup first
- Then Click on Resources –> Recovery Scenario Manager
- Click on New Icon
- Click Next
- Select Popup window radio button & click Next
- Specify pop-up window conditions –> Click on Hand button and click on the required error popup
- Window Title and Window Text are captured
- Click Next and Select Keyboard or mouse operation
- Select “Click button with label” and show the OK button on the popup
- Click Next
- Click Add Another recovery operation (This is because after clicking the OK button on the popup QTP does not close the application)
- Select “Close application process”
- Select the process “flight4.exe” and click Add button
- Click Next (Recovery operations should have two processes)
- Click Next
- Post Recovery Test Run Options –> Select Proceed to next step
- Click Next and specify a name & description
- Click Finish & Save the scenario
Refer the below screenshots:
Record the script:
'Script "Updates an existing Order in the Flight application 'uses date to select the record 'purpose - to demonstrate recovery scenario 'Author - Seetaram Hegde 'Copyrights - All rights reserved 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 "admin" Dialog("Login").WinEdit("Password:").SetSecure "4e987848731bb27320f898d8e4cc58977b0d6b69" Dialog("Login").WinButton("OK").Click Window("Flight Reservation").WinButton("Button").Click Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Flight Date").Set "ON" Window("Flight Reservation").Dialog("Open Order").ActiveX("MaskEdBox").Click 4,6 Window("Flight Reservation").Dialog("Open Order").ActiveX("MaskEdBox").Type "21212" Window("Flight Reservation").Dialog("Open Order").ActiveX("MaskEdBox").Click 5,7 Window("Flight Reservation").Dialog("Open Order").ActiveX("MaskEdBox").Type "0" + micLeft Window("Flight Reservation").Dialog("Open Order").ActiveX("MaskEdBox").Type "0" Window("Flight Reservation").Dialog("Open Order").ActiveX("MaskEdBox").Type micBack Window("Flight Reservation").Dialog("Open Order").ActiveX("MaskEdBox").Type "1" Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click Window("Flight Reservation").Dialog("Open Order").Dialog("Search Results").WinButton("OK").Click Window("Flight Reservation").ActiveX("MaskEdBox").Type micDel Window("Flight Reservation").ActiveX("MaskEdBox").Type micDel Window("Flight Reservation").ActiveX("MaskEdBox").Type "12" Window("Flight Reservation").WinButton("FLIGHT").Click Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click Window("Flight Reservation").WinButton("Update Order").Click Window("Flight Reservation").WinMenu("Menu").Select "File;Exit"
Save the Test as “UpdateOrderRecovery”
Associate the newly created Recovery Scenario with this test.
- Click File –> Settings –> Click on Recovery Tab
- Click Add (+) button and add the recovery scenario
- From the “Activate Recovery Scenarios” dropdown select “On error”
- Click OK
Execute the test and it should first click on the error popup window and then close the flight application.