Do you see 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 then can be used as a standard object to record the test.
How to solve object recognition problem in QTP?
Example of Virtual Object:
Here is a 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 the read what this wizard will do.
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.
Step #3) In this screen you can mark the screen where the object is on your AUT. Click “Mark Object” and choose the object from your AUT.
Step #4) The width and height values for the marked object will be populated once the selection is made. Hit “Next”
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 see identify it based on its parent alone or the entire hierarchy. I am just going to keep the default values and click “Next”
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”
This completes the process for 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.
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:
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”.
At times when you are trying to login 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 login. If your test is to login to Gmail account and as soon as you enter the user ID, password, hit the Sign In button and if your QTP test is expecting to arrive at your inbox 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 Recovery Scenario in QTP:
Step #1) Go to “Resources -> Recovery scenario manager” , click on the “New Scenario” icon.
Step #2) Click Next
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.
Step #4) Using the “Pointed hand” option, choose the window that you would want to add.
Step #5) Define the recovery option by clicking on the “Next” icon below:
Step #6) Choose one from the list. I am going to choose “Keyword or mouse operation”. The options in this screen are really easy to understand. So choose accordingly.
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.
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
Step #9) Enter the scenario name, description and click Next
Step #10) It provides a gist of your scenario. As you can see, there are 3 parts to a recovery scenario. The Trigger, Recovery operation 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 to a test explicitly. Click “Finish”
Step #11) The scenario we just created will appear in the list. Save and close.
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.
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 when practicing the recovery scenarios.
Post your questions below.