July 12, 2012

Object Repository

As you know QTP works on the principal of identifying the objects in the application under test and performing the specified action on that objects. But to work on that objects, the objects should be stored in the object repository.

Object Repository is we can say the heart of QTP where it stores the objects of application under test. While running the test, QTP compares the object available in object repository(called Test Objects) with the objects in application(called RunTime Object). If properties of both test object and runtime object macthes then the specified action is performed on that object.

Types of Object Repositories:
Object Repositories are of two types:
1. Local OR:  By default each action has a local object repository. Local OR is action specific i.e. the objects added to local object repository are available to that action only thats why the local object repository is also called Per-Action Object Repository.When we are recording, the objects are added to the local object repository of that action. Extension for local OR is (.mtr). 
2. Shared OR: Shared object repository can be used by any action in current test and/or any other test. To make a shared object repository:
A. Open object repository window.
B. Select File >> Export Local Objects
C. Select location where you want to save shared object repository.
D. Click on SAVE button.
Now the shared object repository is saved at specified location with all objects of your local object repository. Extension for shared OR is (.tsr)

How to add object to Object Repository:
Objects are added to object repository automatically when we are recording the test in QTP. All the objects that we use while recording gets added to object repository. For example while recording if we click on a link, button then that link/button object gets added to object repository similarly when we enter a value in a text box(like username, password) that text box object gets added to object repository.
But if we are not using recording then we can add object manually. Here are the steps:
1. Open Object Repository from Resources >> Object Repository 
2. Click on the "Add objects to local" icon from toolbar.
3. Now QTP is minimized and application is on front. Click on any object in application.
4. Object selection window is displayed. Select the required object.
5. Click on OK button.
Now the object selected in Object Selection Window is added to your local object repository.

How to associate shared OR with an Action:
1. Open  the test and select the action with which you want to associate shared OR.
2. Go to Edit >> Actions >> Action Properties
3. Select "Associated Repositories" tab
4. see that by default Local Object Repository is associated with action.
5. Click on "+" button.. 
6. Click on "...." button to browse for shared OR.
7. Browse and select shared OR..
8. Click on Ok button.
Now shared OR is associated with the action. If all object of local OR are available in shared also then we can remove those objects from local OR and still your script will work.

Merging two Shared Object Repositories:
Shared object repositories are used so that the same objects can be used by multiple test. We can create a single shared OR by merging multiple shared ORs but at a time we can merge only two shared object reporisories.
1. Select Resources >> Object Repository Manager
2. Now in OR Manager, Select Tools >> Object Repository Merge Tool
3. Browse and Select two shared ORS, one as primary and other as secondary.
4. Click on OK button.
5. Now the merged object repository's objects are displayed in right side .
6. Select File >> Save option. Select location and click SAVE.
Now the merged object repository is saved at specified location. It can be associated with an action in same way as described above.

Editing Shared Object Repository:
Now you have associated a shared objecr repository to the an action. But if you see that object repository now you will find that the objects in shared OR are disabled. You do not have permission to edit the shared OR. But we need to add few more objects to the object repository. This is also possible with help of Object Repository Manager(ORM).
1. Select Resources >> Object Repository Manager
2. Select  File >> Open
3. Browse the Shared OR you want to edit. Its not editable now.
4. Select File >> Enable Editing option.
5. Now you can add objects with help of "Add Objects" icon as described in "How to add object to Object Repository"  section above.

Important Points:
1. Object Repository is centralized place to add object of AUT.
2. Local object repository is given preference by QTP. If both local and shared OR are associated with action then QTP looks for the object in Local OR first and if not found in local then it will look in the shared OR.
3. Shared OR enhances the reusability of the objects so while automating the test we should use shared object repository.
4. If an object with the same name and description is located in more than one shared object repository associated with the same action, the object definition is used from the first occurrence of the object, according to the order in which the shared object repositories are associated with the action.
5. When a Reusable action is called then it brings its associated object repositories also.


  1. its really seems to be positive value addition to your knowledge........its seems to be a Cover object repository..............:)

  2. How to save local object repository

  3. You do not need to save local object repository. Once you add an object to your local object repository, it gets saved automatically.

  4. I read this paragraph completely regarding the difference of latest and earlier technologies,
    it's amazing article.

    My web page

  5. Its a good article, it clear my doubts about object repository. Please write more articles on QTP.


Your kind comments are always welcome. Put your comments here if you have problems in this post or you want me to add something else in this post.