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

By Vijay

By Vijay

I'm Vijay, and I've been working on this blog for the past 20+ years! I’ve been in the IT industry for more than 20 years now. I completed my graduation in B.E. Computer Science from a reputed Pune university and then started my career in…

Learn about our editorial policies.
Updated October 12, 2024

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.

Was this helpful?

Thanks for your feedback!

Recommended Reading

  • Selenium Scripting And Troubleshoot Scenarios

    In the previous tutorial, we discussed the technical implications of implementing logging in a framework. We discussed log4j utility at length. We discussed the basic components that constitute log4j from a usability perspective. With the Appenders and layouts, a user is leveraged to choose the desired logging format/pattern and the…

  • QTP Test Result Analysis

    In this QTP tutorial, we will learn - Smart Object identification, adding Synchronization point, Running a test & viewing the results, and the Silent Test runner. => Click Here For The QTP Training Tutorials Series Assume a situation when no object matches or multiple objects match the recorded description for an…

  • Object Identification Paradigm

    How Does QTP Identify Object Uniquely? - This is the 7th QTP Tutorial in our QTP training series. We are getting ourselves equipped with all the basic concepts that will enable us to write robust QTP tests. We have covered the QTP Record and Run settings, Working with Keyword view,…

  • Techniques for Parameterization

    In part 1 of this QTP Parameterization tutorial, we explained Datatable Parameterization with an example. In this QTP tutorial let’s focus on the remaining three Techniques for parameterization in QTP: 2) Random number parameters 3) Environment variable parameters 4) Test/Action parameters => Click Here For QTP Training Tutorials Series #2 -…

  • Parameterization in QTP

    What is QTP Parameterization? Sometimes the application does not accept duplicate data records. In this case, if you run the same Test script with a fixed set of input data, an application may throw an error due to data duplication. To avoid this issue, QTP provides ways to accept different…

  • QTP Tutorials

    Today we are publishing part one of a multi-part guest post series on Micro Focus Quick Test Professional (QTP). In this multi-part QTP training series we'll be covering all QTP tutorials and concepts in detail with adequate illustrations. Our expert author Swati S. will be helping us in bringing this…

  • Using Text Area, Table, and Page Checkpoints

    In the last article, we were discussing the ways in which QTP can compare text. We also saw how standard checkpoints can be used to check the text and discussed the text checkpoint in detail. The next checkpoint is the Text area checkpoint. Let’s begin exploring it. => Click Here For…

  • Object Repository

    Object Repositories in QTP and Object Repository Manager This tutorial will focus on QTP Object Repositories. In our previous articles, we have discussed how QTP identifies and stores objects in a warehouse, the OR. We have also seen how the object properties appear in the OR. To quickly recap, we…


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

  1. 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?

    Reply
  2. 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.

    Reply
  3. @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.

    Reply
  4. 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?

    Reply

Leave a Comment