Managing Object Repositories in QTP

QTP is having separate window named as “Object Repository Manager” for managing various object repositories.

You can open this window from the Menu “Resources->Object Repository Manager…

The Object Repository Manager enables you to manage all of the shared object repositories used in your organization from a single, central location.
It will be used for adding and defining objects, modifying objects and their descriptions, parameterizing repositories to make them more generic, maintaining and organizing repositories, merging repositories, and importing and exporting repositories in XML format.

The Object Repository Manager window will look like below one.

 

You can create new shared repository from this window and can store it as .tsr file.

While adding objects, you will be provided with two options. Either you can choose to add only the selected Object or you can choose to add the selected object and its descendants.

You can store the object repositories  either in file system or in Quality Center project.

The Object Repository(OR) Manager enables you to open multiple shared object repositories and modify them as needed.

This Object Repository Manager provides the options such as  “Add objects”, “Highlight in Application”,  and “Locate in Repository”  for the Shared object repository. It is similar to the local object repository. I will be explaining them in separate post.

By default this OR Manager will be in readonly mode. i-e you can not edit anything in this mode.

We need to choose File>Enable Editing for making it editable.

Update from Local Repository option in the OR Manager (Tools > Update from Local Repository) can be used for merging objects from the local object repository of one or more actions to a shared object repository.

And, it provides Object Repository Merge Tool for merging two shared object repositories.

At the end of the merge process, the Object Repository Merge Tool provides a graphic presentation of the original objects in both repositories, which remain unchanged, as well as the objects in the merged target object repository.

Objects that had conflicts are highlighted. The conflict of each object that you select in the target object repository is described in detail. The Object Repository Merge Tool provides specific options that enable you to keep the suggested resolution for each conflict, or modify each conflict resolution individually, according to your requirements.

And note that while the Object Repository Merge Tool is open, you cannot work with the Object Repository Manager.

Apart from this OR Manager, QTP is having “Associate Repositories” option for  enabling you to associate one or more shared object repositories with one or more actions in a test.

 

Different Types of Object Repositories

In this Chapter I will explain various types of Object repositories (OR).

You should be familiar with “What is Test?” and “What is Action?” in QTP for understanding the types of object repositories.

There are two types of Object Repositories available in QTP.

They are,

1. Local object Repository (Previously it was called as per-action)

2. Shared Object Repository.

Local Object Repository

Local Object Repository stores Test Objects in a file associated with each Action. i-e Each action will have its own local object repository.

These objects can be edited from the corresponding Action.

This local object repository can NOT be used and/or edited by any other Actions within the same Test.

You can see separate ObjectRepository.bdb file inside each Action sub folder within the Test folder when you see them thro’ windows explorer.

The local object repository will be created automatically and the Test objects will be automatically stored in the Local repository while doing recording.

Shared Object Repository

A shared object repository stores test objects in a file( normally .tsr file) that can be accessed by multiple Actions/Tests in read-only mode.

We need to create this Shared Object Repository manually from Object Repository Manager.

We can export the local object repository objects into the Shared Repository file.

Associating Repositories

Each Action can use the objects from local object repository and from multiple shared object repositories.

Association of Object repositories can be done easily from the “Associate Repositories” Dialog window which will be opened from Tools->Associate Repositories menu in the Object Repository window.

By storing objects in shared object repositories and associating these repositories with Actions/Tests in your Test, you enable multiple Actions/Tests to use the objects.

It will improve maintenance of the script.

Since each Action is allowed to take objects from many places (Local object repository and multiple Shared object repositories), you should know how QTP will handle if object with same name is located in more than one repository.

QTP will give high priority to the local object repository. It will use the object from the Local object Repository if it finds object with same name in many repositories.

And, if more than one shared object repositories are having same object (i-e object with same name, properties may vary), QTP will use the object based on the order of association.

Since the shared object repository improves maintenance and enhances the re-usability, we should use them in our Automation project.

Local object repository can be used for learning purpose. Since they are getting created automatically, it will be easy to use for the beginners.

Understanding Object Repository

Object Repository is a centralized place for storing Properties of objects available in AUT (Application Under Test).

Why Centralized place? And, Why we should store the properties of objects available in AUT?

First, I will explain below things which will be helpful for understanding answers of above questions.

– All software applications and websites are getting developed using many different components or small units (e.g textbox control in vb, input tag in HTML, webbrowser contorl in .net) which can be called as Objects.

– Each object will be identified based on the object type. And also, each object will have its own properties (e.g name,title,caption,color,size) for helping to identify by each of them. And also, each object is having specified set of methods.

– Some of the properties can be changed during run-time. These are known as RO (Runtime object) properties. And some of them can not be changed. They are known as TO (Test Object) properties.

– You can use ObjectSpy available in QTP IDE to see the TO properties & methods and RO properties & methods of any object available in your application. (Make sure that required add-ins are available).



If you see TO and RO properties of many objects in different applications using ObjectSpy, you will be in a position to distinguish between TO and RO properties.

– Since TO properties are used for uniquely identifying any object, QTP will store only the TO properties of any object in the Object Repository.

– QTP will store TO properties of any object of AUT in Object repository as Name & Value pair. You can refer the below screenshot.

 


– The Objects stored in the Object repository(OR) are called as Test Objects. Actually it is just equivalent to the corresponding actual object in AUT.

– All the Test Objects that are stored in Object repository(OR) are arranged in a hierarchical structure. (e.g Browser->Page->webelement).

– QTP will store the TO properties of the Objects in many different ways.

  • One simple way is, while doing Recording the TO properties will be stored to the OR.
  • Second way is, TO properties can be stored by pointing the mouse cursor to required object in the AUT.
  • Another way is manually adding the TO properties of the objects to the OR.

– Note that QTP won’t store all the TO properties of the objects into the Object Repository. Only few properties will be stored to the OR, based on the setting done in Object Identification window. Refer the below screenshot. It can be opened from QTP IDE (Tools->Object Identification).


-Sometimes, QTP will store some additional properties such as index, location which are known as ordinal identifiers. Actually these properties won’t be available in the object of AUT. It will be created by QTP automatically to distinguish two objects which are having exactly same TO properties. (e.g Some forms in the web pages will be have two submit buttons, one at top and another at bottom. QTP can identify them only based on location or index).

-Note that even QTP is storing TO properties based on properties of object of AUT (i-e real object), there is no need for all the TO properties to be available in RO properties collection also. (ie) QTP can derive (i-e do some manipulation) to get some new TO properties from one or many RO properties.

-Script can get TO properties of Test Objects using methods such as getTOproperty and getTOproperties. Even, TO property of TestObject can be changed using setTOproperty. But anyway, it will be valid only till exiting the execution. After completing the execution it will resume the actual TO property stored in the OR.
During run-time we can get the property of the runtime object using getROproperty.

-Till this point we have seen about storing the Test Objects in Object Repository.
During Run mode, QTP will use these stored properties for comparing them with properties of actual objects of AUT to identify them.

– These Test objects can be represented in the script as ObjectType and Object name. (e.g Window(“Mozilla Firefox”).Activate).

– The object repository will support editing of properties of Test Object and new properties can also be added to them.

– The value for the properties of the Test Objects in OR need not be a constant. We can parameterize the values so that the TO property can be dynamically changed for each iteration of execution.

Now we can come to our Initial question. By storing properties in the centralized place, maintenance and updation of Test scripts can be easily done whenever there is a change in UI (User Interface) of the AUT.
Assume that Login screen is used in around 20 Test scripts. If the Page name of login screen in changed, we need not make any change in all these 20 Test scripts. Just changing the property of Test Object in OR is enough.

Clear understanding of Object Repository is essential if you are willing to use QTP extensively. Because we may face lot of difficulties/challenges while working with QTP. We should have clear knowledge in OR to face/solve them. Just Recording and Playback won’t help much. And also, Test Automation framework can be done very effectively only when you are familiar with understanding/handling of Object Repository.