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 will take a look at the OR screen. You can launch it from your current test by clicking on the icon
=> Click Here For QTP Training Tutorials Series
Table of Contents:
Object Repository in QTP
It launches the following Object repository dialog box:
Points to note here:
- The objects are stored in a hierarchical manner.
- This is a local repository that contains the objects for Action1.
- If the action had any checkpoints, then the same would have been available in this dialog to edit.
We have also made multiple references to Shared ORs in our previous articles. Let us learn all about them.
A Shared Object Repository stores objects in a file that can be accessed by multiple tests (in read-only mode).
One of the important aspects while planning your tests (or choosing a framework for your project) is to consider where and how you want your objects to be stored and how they have to be made available to the tester.
Object Repository Types in QTP
Given below are some Object Repository types in QTP:
- Local ORs – Each action will have its objects stored in its local repository.
- Shared ORs – All actions will refer to a single read-only OR.
- Local and Shared ORs – An action can use both local and multiple shared ORs.
In one of our previous tutorials, we talked about how objects get selected if a certain action has both Shared OR and Local OR, multiple shared ORs, etc.
We will see how a shared OR is created and how we can move objects to and from a shared OR to local or vice versa.
To maintain ORs in your test there is a specialized Object Repository Manager that QTP provides. It can be accessed from the menu item “Resources -> Object Repository Manager”.
Using ORM you can do the following:
- Creating New Object Repositories in QTP
- Opening Object Repositories
- Saving Object Repositories
- Closing Object Repositories
- Managing Objects in Shared QTP Object Repositories
- Managing Repository Parameters
- Modifying Object Details
- Locating Test Objects
- Performing Merge Operations
- Performing Import and Export Operations
In this example, we will see how to create a shared OR for a test, understand how it can be associated, and see how the objects can be used.
To create a shared OR (.tsr) file, launch ORM. A new repository will open up or you can explicitly do so by using the option “File -> New”. Any OR is only as good as the objects it has. So the next step is obviously to add objects.
There are 3 ways you can do that from here:
Method #1: Define Test objects. “Object -> Define Test Object” – on choosing this option, the following dialog appears:
Here, you can specify the environment, Class, Name, Properties and Add the object to the repository. The screenshot can be a sample data you can enter.
Method #2: Add Objects: On choosing this option, the pointy hand gets active, QTP gets minimized and when you click on the object you wish to add, the following dialog shows up and you can add the object.
Method #3: Navigate and Learn: This is the most interesting and commonly used way. As the name indicates, you just have to instruct QTP to ‘navigate and learn’, point to an object in your app and QTP automatically gets the objects depending on your filter settings.
Choose this option from the menu or hit F6, in the screenshot notice a little navigate and learn dialog at the top of the page. Now Hit the Learn button in the dialog and click on the page. Navigate to as many pages and hit learn as many times as required. Once done, close the “Navigate and Learn” dialog.
The filter options are as follows:
I chose “All Object Types” from the dialog and clicked on the main gmail.com page. The following are the objects that get added to the OR:
Using any of the above ways to create a shared ORM, add objects, and save it.
There is another way in which objects can be added to a shared OR. It is from the local OR.
Open your test or create a new test. Gmail Login – an example of ours. Launch the OR for this test.
It looks like this:
I want to create a shared OR that contains the email, password, and sign-in objects. The “File” menu has 2 options under it, “Export Local Objects” and “Export and Replace Local Objects”. You can use either one of these options.
If you use “Export Local Objects”, the local objects are exported to the specified shared object repository (a file with a .tsr extension). Your test continues to use the objects in the local object repository, and the new shared object repository is not associated with your test.
With “Export and Replace Local Objects”, the new shared object repository (a file with a .tsr extension) is associated with your test, and the objects in the local object repository are deleted.
Choose any of the options and choose the shared OR to export to.
After you decide to use a shared OR for your test, create one and add objects to it, the tester has to explicitly include the .tsr file for the test to be able to use the objects in it.
To do so, go to “Resources ->Associate Repositories”.
The following dialog box opens up:
Click on the “+” sign. Choose OR. Once you choose it, all the actions that are available in your test will appear under the “Available Actions” box.
Select as many or as few as you would like. I only have one, so I am going to go ahead and choose it. Click OK when done.
On successful association, the shared OR will appear in the Resources pane if it is already visible or you can launch the same from the “View -> Resources” option.
If you want to remove the association, you can right-click on the .tsr in the resources pane and select the “Remove Repository from List” option. Or you can go to the “Resources -> Associated Repositories” menu option, select the shared ORM to remove, and click on the cross sign.
For rules on how a shared OR and Local OR will work, please refer to our tutorial #8. Though there are many other features to ORM and OR, we will limit ourselves to what we have learned in this article as they are the most useful ones. The rest of them are very easy for any tester to figure out on their own once they read this article.
I hope we simplified the process of using Object Repository in QTP.
=> Visit Here For QTP Training Tutorials Series
Please feel free to post your questions if any.
Thanks for the detailed tutorial on qtp OR and ORM.
Nice explanation…
How to navigate to object Repository manager, Can any body guide me..I am unable to see “Resources->Object Repository Manager” in my QTP menu list
Hello ,
I have a question, please look at my code below:
JavaWindow(“ABC”).JavaDialog(“Add”).JavaEdit(“JTextArea”).Set(“123”)
When i run my code … JavaDialog change every time from and expects different code each time and i have to change code to any of following:
JavaWindow(“ABC”).JavaDialog(“Add”).JavaEdit(“JTextArea”).Set(“123”)
OR
JavaWindow(“ABC”).JavaDialog(“Add_2”).JavaEdit(“JTextArea”).Set(“123”)
JavaWindow(“ABC”).JavaDialog(“Add_3”).JavaEdit(“JTextArea”).Set(“123”)
why does it change every time. how can i write a code that run every time without changing anything?
Hi Vijay
I have one question, in QTP after executing the script will it be the final script because again in QC we execute the same script from Test Lab. Why we should execute 2 times from QTP and QC. And from QTP directly we can add the defect after executing the script?
Thanks
Hi,
I need a clarification regarding QTP 10 objects identification.
object spy recognizing web objects as windows even though i selected for correct add-ins.
please help me in this regards.
Please try to open qtp first and then the web application. This should help
I have question…does it always require to run script to add object repository.
Hi Vijay
I have one question, in QTP after executing the script will it be the final script because again in QC we execute the same script from Test Lab. Why we should execute 2 times from QTP and QC. And from QTP directly we can add the defect after executing the script?
Thanks