Friday, June 30, 2006

More about Object Repository Files [ADVANCED]

To be able to mimic what was done by a user, QTP learns the object the user interacts with by recording enough properties of the object to be able to uniquely identify the object. This, as you know, in QTP is the object repository. The object repository is simply a file that has to be stored on the system. QTP uses two file types for doing this. A TSR file and and MTR file.

TSR file
This is the file type QTP uses to store an object repository when you choose 'Shared' mode in Test->Settings->Resources. The TSR file must then be referenced by any test that wants to use the objects within that repository.
What we do is learn all the objects within an application and store it inside a single file, therefore anytime you want to test that object, you simply have to load the correct TSR file.

How to create a TSR file
There are two forms for doing this.
1. Create a new test, open the Object Repository by clicking Tools->Object Repository. From the tools use 'Add New Object' to add the objects you want. Then click 'Export' and choose a filename.tsr to save the object repository as.
2. Create a new test, open the Resources tab at Test->Settings->Resources. Type in the name of the tsr file you want to create. It will prompt you that you are creating a new file, say yes. Open the Object Repository by clicking Tools->Object Repository. From the tools use 'Add New Object' to add the objects you want. Then click 'Save'.
Note: In 1, you export, in 2, you save

MTR file
A second, but much lesser used for is the 'Per Action' object repository. In this form, you do not worry at all about your object repository. Sounds too good to be true, and it is. The problem with this form is that if anything changes in the application, you have to go back and re-record ALL the actions that use the changed object. This form is almost only used when testing a mature application, i.e. one in which you know (with great certainty) that the GUI objects will not change.