Object Repository in QTP – Tutorial #22

Object Repositories in QTP and Object Repository Manager

Today’s topic is QTP Object repositories. In the previous articles, we have discussed how QTP identifies and stores objects in a warehouse, the OR. We also have 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 QTP Object Repositories icon or from the “Resources->Object Repository” option.

It launches the  following Object repository dialog box:QTP Object Repositories

Points to note here:

  1. The objects are stored in a hierarchical manner.
  2. This is a local repository that contains the objects for Action1.
  3. If the action had any checkpoints the same would have been available in this dialog to edit.

We also have 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 when 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.

The following are some Object Repository types in QTP:

  1. Local ORs– each action will have its objects stored in its local repository
  2. Shared ORs – all the actions will refer to a single read only OR
  3. Local and Shared ORs– an action can use both local and multiple shared ORs.

In one of our previous tutorial 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 do that from here:

Method #1) Define Test objects. “Object->Define Test Object” – on choosing this option the following dialog appears:

QTP Object Repositories

In here, you can specify environment, Class, Name, Properties and Add the object to the repository. The screenshot can be a sample data you could 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.

QTP Object Repositories

Method #3) Navigate and Learn:  This is the most interesting and most 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 the little navigate and learn dialog on the top of the page. Now Hit the Learn button in the dialog and click on the page. Navigate as many pages and hit learn as many times as required. Once done, close the “Navigate and Learn” dialog.

------------

QTP Object Repositories

The filter options are as follows:

QTP Object Repositories

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:

QTP Object Repositories 6

Using any of the above ways create a shared ORM, add objects and save it.

There is another way objects can be added to a shared OR. It is from the local OR.

Open your test or create a new test. Gmail Login- our example. Launch the OR for this test. It looks like this:

QTP Object Repositories

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.

Associating the shared Object Repository to your test

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 to 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:

Associating the shared OR to your test

Click on the “+” sign. Choose the 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 just have one, so I am going to go ahead and choose it. Click OK when done.

Associating the shared OR to your test

On successful association, the shared OR will appear in the Resources pane if it is already visible or you can launch the same from “View->Resources” option.

Associating the shared OR to your test

If you want to remove the association, you can right click on the .tsr in the resources pane and select “Remove Repository from List” option. Or you can go to “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.

Hope we simplified process of using Object Repository in QTP.

In any case, please post your questions if you should have any.




8 comments ↓

#1 Meghraj Arne

Thanks for the detailed tutorial on qtp OR and ORM.

#2 Hitesh

Nice explanation…

#3 PK

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?

#4 jaggarao

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.

#5 faraaz

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

#6 faraaz

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

#7 Pallavi

I have question…does it always require to run script to add object repository.

#8 Mani

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

Leave a Comment