QTP Tutorial #24 – Using Virtual Objects and Recovery Scenarios in QTP Tests

Do you see an object not found error while running QTP tests? Well, this is because, during playback, QTP can’t recognize non-standard objects. To solve this object recognition problem, we use Virtual Objects.

Using Virtual Object Wizard we can map these unrecognized objects to a standard class which can then be used as a standard object to record the test.

=> Click Here For QTP Training Tutorials Series

Using Virtual Objects and Recovery Scenarios

Virtual Objects in QTP

How to solve the Object Recognition problem in QTP?

Example of Virtual Object:

Here is the scenario: I am recording a test on a Microsoft word document. I activate the already opened MS word doc and I click on any of the icons in the top menu. For example, I click on “Format Painter”. The code that gets recorded into QTP is:

Window(<Microsoft Word>).WinObject(<NetUIHWND>).Click 132,120
Window(<Microsoft Word>).WinObject(<NetUIHWND>).Click 672,101

In cases like this, we would go for a virtual object. By definition, a Virtual Object is an object that is recognized by QTP as non-standard but is instructed explicitly by the tester to behave like a standard object.

Virtual Object Wizard Steps

Step #1: Go to the menu option “Tools -> Virtual Objects -> New Virtual Object” and click “Next” in the following window.

Before you hit “Next” take a minute to read what this wizard will do.

Virtual Objects

Step #2: Here you will find a list of classes. You can choose any class depending on how the object in your application is behaving like. In our case, the “Format Painter” icon is more like a button. So I am going to choose “Button” from the list.

Virtual Objects

Step #3: On this screen, you can mark the screen where the object is on your AUT. Click “Mark Object” and choose the object from your AUT.

Virtual Objects

Step #4: The width and height values for the marked object will be populated once the selection is made. Hit “Next”.

Virtual Objects

Step #5: You can now configure the way in which you would want the selected object to be recognized with reference to its parent. As you can see, you have a choice to identify it based on its parent alone or the entire hierarchy. I am just going to keep the default values and click “Next”.

Virtual Objects

Step #6: Give your virtual object a name and add it to a collection (nothing but a consolidated list of Virtual objects). I keep the default values and click “Finish”.

Virtual Objects

This completes the process for the creation of a Virtual Object.

Step #7: Go to “Tools -> Virtual Objects -> Virtual Object Manager”. Here you can see all the collections that are available and the objects within them.

Virtual Objects

Clicking on “New” will take you back to the creation process that we have just seen. You can delete a collection using the “Delete” button.

Once you are done creating the virtual object, repeat the recording process on your AUT for the same object. This is how the code looks:

Window(<Microsoft Word>).WinObject(<NetUIHWND>).VirtualButton(<button>).Click

Now you will be able to perform all the operations on this VirtualButton that you can on a standard button object.

A few points to note:

#1) This feature is not available for Analog and low-level recording modes.

#2) From the example, you can see that the virtual object completely relies on the width and height factors, so it is not highly reliable.

#3) To disable QTP from recognizing the virtual objects while recording, choose the option “Disable recognition of virtual objects while recording” under “Tools -> Options -> General”.

Virtual Objects

Recovery Scenario in QTP

At times when you are trying to log in to your Gmail account, assume a pop-up window comes up and you will be asked to confirm your security information. This does not happen every time you log in.

If your test is to log in to the Gmail account and as soon as you enter the user ID, password, hit the Sign In button, and if your QTP test is expected to arrive at your inbox, then your test is going to fail if the security information screen comes up randomly.

To handle cases like this, we use the ‘Recovery Scenarios”.

Steps To Create A Recovery Scenario In QTP

Step #1: Go to “Resources -> Recovery scenario manager”, click on the “New Scenario” icon.

Recovery scenario

Step #2: Click Next

Recovery scenario

Step #3: The trigger for this to start could be one of the following options. Choose according to your scenario. In our case, I will choose, Pop-up window. The other options are self-explanatory.

Recovery scenario

Step #4: Using the “Pointed hand” option, choose the window that you would like to add.

Recovery scenario

Step #5: Define the recovery option by clicking on the “Next” icon below.

Recovery scenario

Step #6: Choose one from the list. I am going to choose “Keyword or mouse operation”. The options on this screen are really easy to understand. So choose accordingly.

Recovery scenario

Step #7: I am going to go with the default settings and click Next. The recovery operation gets added to the list. If you need to add more than one recovery operation, you can keep the corresponding checkbox checked and click Next. It will take you back to the screen in Step number: 5. Or, if you are done, you can simply uncheck the checkbox and click on “Next”. That is what I am going to do.

Recovery scenario

Step #8: Now you will have to define the post-recovery operations.  All the options are as their names indicate. I am going to choose “Proceed to next step”. Click Next.

Recovery scenario

Step #9: Enter the scenario name & description and click Next.

Recovery scenario

Step #10: It provides a gist of your scenario. As you can see, there are 3 parts to a recovery scenario. Trigger and Recovery operations and post-recovery operations.

You can choose to add this scenario to the current test or to all tests by choosing the relevant checkboxes. I am going to keep them unchecked at this point because I want to show how a tester can associate them with a test explicitly. Click “Finish”.

Recovery scenario

Step #11: The scenario we just created will appear in the list. Save and close.

Recovery scenario

Step #12: Associating the recovery scenario. Open a test, in the “Resources” pane, right-click on “Associated Recovery scenarios”, right-click and choose “Associate recovery scenario”. Browse for the scenario and click “Add Scenario”. The chosen scenario will appear in the list in the Resources pane.

Recovery scenario

Step #13: Also, you can go to “File -> Settings -> Recovery” and add the scenarios you would like. Here you can also choose the options as to how often you would like it to run. You can choose to run it, On Error, On Every Step, or Never.

Step #14: The extension for a recovery scenario file is “.qrs”

This concludes our discussion on Virtual Objects and Recovery scenarios. I would recommend the tester to use various combinations of Trigger, Recovery, and post-recovery operations while practicing the recovery scenarios.

=> Visit Here For The QTP Training Tutorials Series

Post your questions below.

Recommended Reading

8 thoughts on “QTP Tutorial #24 – Using Virtual Objects and Recovery Scenarios in QTP Tests”

  1. more examples of which objects are not identified by qtp? I mean what type of objects are considered as non-standard objects qtp unable to identify?

  2. thank you for this tutorial

  3. Smriti

    Those objects on which we get code like
    window(“Microsoft Word”).WinObject(“btnUFD”).click “35,45”

    Specially this “35,45” on these scenarios we use Virtual Objects.

  4. @Ankur: Thank you Ankur for answering the question.

  5. @Smriti: To add to Ankur’s answer I would say that you explore a couple of applications and try using QTP on them. That way, this concept is going to make sense.

  6. Thank you for posting such a useful topics.

  7. Hi sir
    This is chandrasekhar
    i am asking a quation
    1.How to Access the test case one Action to Anather Action?
    2.How to crate vertual Objects?
    3.When chose the Recover secnarios in testng process?
    4.how post the defect in QTP?
    5.every test case develop independent or Not?
    6.how to write environment veriables?

  8. Really Helpful… Thanks


Leave a Comment