Thursday, April 26, 2007

Object Repositories in QTP 9 (QuickTest Professional)

An object as we know is a graphic user element in an application e.g. a button or a list or an edit box and the special characteristics of an object within the QuickTest are called object properties. QTP stores the recorded object properties in Object Repository.

In this article I will be talking about Object Repositories to an extent.

[For more information on Object Repositories you can see the QTP user guide.]

Object Repositories are of two types Local and shared .

If objects are stored in a Local Object Repository then these are available to specific actions but not to all the actions. But if these objects are stored in one or more Shared Object Repositories then multiple actions or tests can use them.

By default QTP makes and uses Local Object Repository. If we create a new blank test and do a recording on it, QTP automatically creates a Local Object Repository for that test or action and stores the information about any object it finds in that corresponding Object Repository.

In QTP 9 we can associate multiple Shared Object Repositories with an action. If multiple Shared Object Repositories are associated with an action then also while recording QTP stores objects in corresponding Local Object Repository on the condition that those objects are not already stored in any corresponding associated Shared Object Repositories. This is the default that every time we create a new action QTP creates a new corresponding Local Object Repository. It is also true that Object Repositories are associated with actions and no matter how many times we learn or record on the same object in our application in different actions the object will be stored as separate test object in each of the Local Object Repository. Local Object Repository is automatically saved with the test when we save it. The extension of the Local Object Repository is .mtr, but it is not accessible as a separate file as in case of the Shared Object Repository.

We can also manipulate some aspects of Local Object Repository using Quick test Object Repository Automation Object Model.
For example we can add, remove, rename test objects in Local Object Repository. [QuickTest Object Repository Automation documents the Object Repository automation object model that enables you to manipulate QuickTest object repositories and their contents from outside of QuickTest.]

When we open a test that was created using a version of QTP earlier that version 9 we are asked whether we want to convert it or view it in read only format. In any case if the test previously used per-action Object Repository, the objects in each per action repository are moved to the Local Object Repository of each action in the test.

If the test previously used a shared object repository, the same shared object repository is associated with each of the actions in the test, and the local object repository is empty.

While learning or recording we can specify Shared Object Repository for the selected action. We can specify and associate one or more Shared Object Repositories with each action. We can also create new Shared Object Repository and associate it with our action.

In case of Shared Object Repository, QTP uses existing information and does not add objects to the Object Repository if we record operations on an object that already exists either in Shared or Local Object Repository.

As said earlier QTP does not add objects directly to the associated Shared Object Repository as we record, instead it adds new objects in Local Object Repository (if that object does not already exist in associated Shared Object Repository).

We can surely export Local objects to Shared Object Repository.

There are different ways in which we can move objects from Local Object Repository to Shared Object Repository:

Exporting the objects to the Shared Object Repository from the Local Object Repository:

In Object Repository window choose the action whose local objects you want to move. Choose File-> Export Local Objects.Select the location in which you want to save the file. Click on save.

We can update the Shared Object Repository with the Local Object Repository:

If we create a new test it will be created with Local Object Repository, we can associate any new or old Shared Object Repository with it, and so we can update that Shared Object Repository with Local Object Repository.

In Object Repository Manager open the Shared Object Repository (clear open in read only check box).

The test in this case should not be open. In Object Repository Manager go to Tools –> Update From Local Repository. Select the test who's Local Object Repository you want to use. Click update all. It will move all the objects to the Shared Object Repository.

We can also merge objects from two Object Repositories (called as primary and secondary in QTP 9) into a new single Object Repository (target Object Repository in QTP 9). The original source files are not changed. It also enables you to merge objects from Local Object Repository of one or more action(s) into a Shared Object Repository. It is recommended to use as a primary Object Repository the file in which you have invested alot of your effort, like which has more number of objects.

If we do not specify a file extension for Shared Object Repository when creating a new Shared Object Repository QTP automatically appends a default extension name for Shared Object Repository as .tsr. This means that we can create Shared Object Repository with any extension other than .tsr, it should work fine (I have tried that and it works fine), I think it may create problems while merging two Object Repositories (I haven't tried that yet).

We can compare two Object Repositories using the Object Repository Comparison Tool. The tool enables you to identify similarities, variations or changes between two Object Repositories.

We can also copy objects to Local Object Repository from the Shared Object Repository. We can copy, paste and move objects in Local Object Repository and copy, paste and move objects within Shared Object Repository and between Shared Object Repositories.As said earlier we can also copy objects from shared Object Repository to Local Object Repository to modify them locally.
We cannot remove an association between the action and its Local Object Repository.

I had one question which I asked in the forum also and still I am unable to get an answer to this:

The answer to the question which I asked above is:

According to QTP user guide:
You can associate as many object repositories as needed with an action, and the same object repository can be associated with different actions as needed. You can also set the default object repositories to be associated with all new actions in all tests.

Whenever we make any changes to an Object Repository those changes are automatically updated in all the associated tests open on the same computer as soon as we make the change even if the Object Repository is not yet saved and if we close the same Object Repository without saving the changes the changes are rolled back in any open tests. For the test that was not open when we changed Object Repository, when we open the test on the same machine on which we modified the Object Repository the test is automatically updated with all the saved changes. To see saved changes in a test or repository open on a different computer, you must open the test or object repository file or lock it for editing on your computer to load the changes.

Important points about Object Repositories

It is a point to consider while planning and creating test that how you want to store objects; either you want to store them in Local Object Repository or Shared Object Repository.

For each action, we can also use a combination of objects from the Local and Shared Object Repositories, according to our needs. Local objects can also be transferred to a shared object repository, if necessary. This will cut maintenance and increase the reusability of the tests because it will enable us to maintain the objects in a single, shared location instead of multiple locations.

If there is a same name object in both the Local Object Repository and in a Shared Object Repository associated with the same action, the action uses the local object definition i.e. the local object is given preference over the shared object. If an object with the same name is stored 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.

When we open an existing test, it always uses the object repositories that are specified in the Associated Repositories tab of the Action Properties dialog box or in the Associate Repositories dialog box. When we access Shared Object Repositories from tests they are read-only; we can edit them only using the Object Repository Manager.

As and when an application under test changes, such as when a "Log in" button is renamed "Sign Into," we can make one update to an XML-based Shared Object Repository (within the new Object Repository Manager), and the update will circulate (propagate) to all tests that reference this object. QuickTest Professional keeps object-level changes synchronized among users throughout test creation efforts.

Object Repository dialog box

Object Repository dialog box window shows a tree of all the objects (either Local or Shared) on its left hand side in the selected action. On selecting any object in the tree Object Repository window shows the information about the object like the name, repository in which it is stored etc. On the left hand side in a tree local objects are editable while the shared ones are grayed out (non-editable).

To view the test object properties, to modify test object properties and to add objects to Local Object Repository we can use Object Repository window. We can also delete objects from Object Repository window; this is needed as when an object is removed form the test it is not automatically removed from the Local Object Repository.

Object Repository in QTP is XML based means that if we change something related to the object in Shared Object Repository., the change will be propagated to all the tests that reference this object, in real time.

Adding Objects to Repositories
[Please see QTP user guide for in-depth information on these below points.]

We can add objects to Shared Object Repository or Local Object Repository in a number of different ways-

We can decide whether to add only a selected object, or to add all objects of a certain type, such as all button objects, or to add all objects of a specific class, such as all WebButton objects.

We can modify objects stored in a Local Object Repository using the Object Repository Window and objects in a Shared Object Repository using the Object Repository Manager.

It is possible to add objects to the object repository before they exist in an application.

We can also add objects to the Local Object Repository while editing our test.

We can add the object directly to a Shared Object Repository using the Object Repository Manager, so that it is available in all actions that use this Shared Object Repository.

If needed, we can merge test objects from the Local Object Repository into a Shared Object Repository.

We can also add objects to a Shared Object Repository while navigating through the application ("Adding Objects Using the Navigate and Learn Option").

We can also add an object to the Local Object Repository by choosing it from the application in the Select Object for Step dialog box (from a new step in the Keyword View or from the Step Generator).

We can add objects to the object repository using the Add Objects to Local or Add Objects option.

We can add objects to the Local Object Repository of the current action by selecting the required object in the Active Screen.

Also See:

Parameterize Descriptive Programming
Important QTP Descriptive Programming Questions
Descriptive Programming in QTP
Object Repositories VS Descriptive Programming