Sunday 24 March 2013

Use of Recovery Scenario Manager in QTP

When programming with QTP, you may face a situation where pop ups will come on the top of application or application crashes at any point of time. These pop ups will make the objects invisible on the screen Thus it hampers the execution of test in QTP. All these events are not expected and we don't know when these events will happen while execution is going on.

So it is necessary to handle unexpected events in the application to ensure smooth and unattended run of test execution. This is when recovery scenario manager comes into picture.
  • Go to recovery scenario manager from resources menu in QTP.
  • Select Trigger Event as pop up window or object state or test run error or app crash, .
  • In next step, provide the title of pop up window or more details of the event.
  • In next step choose, recovery operation. You may choose to call a function or press any key.
  • In next step provide the post-recovery operation like proceed to next step.
  • In last step give recovery scenario name to this scenario and save this in file .qrs.
In recovery operation, if you have selected to call a function, you must write a function to handle the pop up or perform any kind of recovery operation like restarting the application.

Thus Recovery scenario manager in QTP is used to handle exceptions to ensure unattended execution of test batch.

Recovery Object in QTP.

Now let us see how we can manipulate recovery scenarios using code. We can do below operation using code.

  1. Add or removed specific recovery scenario to current test.
  2. Enable or disable a recovery scenario.
  3. Change the priority order of recovery scenario.
  4. Find the total number of recovery scenarios associated with current test.

Recovery object has below methods.

  1.  Add  - Adds the specific recovery scenario to the specific position in current test.  
  2.  Find  -  Gets the position of the specific recovery scenario in current test.  
  3.  MoveToPos - Changes the priority of the recovery scenarios. 
  4.  Remove -  Removes the specific recovery scenario from the current test.  
  5.  RemoveAll -  Removes all recovery scenarios from the Recovery collection.  
Recovery object has below properties.
  1. Count     - returns the total number of recovery scenarios associated with test
  2. Enabled - enables or disables the specific recovery scenario.
  3. Item       - returns the recovery scenario at specific position.
Example -

'Launch QTP and create new test.

Set qtpObj = CreateObject("QuickTest.Application") 
qtpObj.Launch 
qtpObj.New
qtpObj.Visible = True


 ' Return the Recovery object for the current test 
Set recoveryObj = qtpObj.Test.Settings.Recovery


 'Print the count of recovery scenarios.
Print recoveryObj.Count 


' Add recovery scenarios 
recoveryObj.Add "D:\Recoveryfile.qrs", "Popup", 1 
recoveryObj.Add "D:\Recoveryfile.qrs", "objDisabled", 2

 
' Enable all recovery scenarios that we added in above steps
For i = 1 To recoveryObj.Count 
    recoveryObj.Item(i).Enabled = True
Next 

' Enable the recovery mechanism. Please note that enabling the recovery mechanism is 'different from enabling the recovery scenarios. Even if you enable recovery scenarios but 'do not enable recovery mechanism, recovery operation will fail.

recoveryObj.Enabled = True 

In above example, we have added and enabled 2 recovery scenarios. So if during execution, any pop up comes, that will be handled by scenario 1. If QTP tries to perform any operation on disabled object, that will be handled by scenario 2.

You can learn more about recovery scenarios here.

No comments:

Post a Comment

Please Leave your reply. We value your feedback and inputs

Best QTP Books

Everything About QTP

Hello Friends,
You can find QTP study material, Multiple choice questions (mcq), QTP question bank, QTP question papers, QTP notes, QTP questionnaire, scenario based QTP interview questions, QTP tutorial and QTP training on this site.

If you are a fresher or experienced QTP professional with (1/2/3/4) years of experience, this blog is just for you.