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.
What You Will Learn:
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.
Please feel free to post your questions if any.