An Object is an element that is present in the application . All the elements of the applications are considered as objects. Each object belongs to particular class like list box, edit box, button. image, link etc.
Object Repository is a collection of object and properties with which QTP will be able to recognize the objects and act on it. When a user records a test, the objects and its properties are captured by default. Without understanding objects and its properties, QTP will NOT be able to play back the scripts.
“Object repository acts as a container to store test objects. Test object is the object created by QTP in the test script to represent the object present in the application.”
To open an Object Repository choose “Resources >> Object Repository”.
Object repository looks like below screen –
Object Repository – Features
- We can add the properties by clicking on “+” button and remove it using “x” button. If we want to restore to defaults we can click on the “circular arrow” button
- One can change the object’s Logical Name. Here the name of the object is “Numbers” that can be renamed to “num” which will NOT have any effect on identifying the object uniquely because only the Object’s Name is changed not its Properties. If there is a change in logical name, the same name should be used in scripting.
- Properties of any object must be unique so that QTP will be able to recognize the objects. If the object properties are same for two or more objects then during execution an error would be thrown that “More than one object is matched for the specified properties”.
- After adding the objects, the same can be used in script by simple drag-drop. When the object is dragged and dropped, the default operation is set. Like: Click for a button, Set for a Text Box etc
Run-time Object – The actual object that is present in the application on which the QTP performs an operation. For example search button of Google application on which QTP test clicks when the test runs is referred as Run Time object as shown in below –
Object Spy:- Object Spy is used for viewing the Properties and Methods of any object in an application. You use the Object Spy pointer to point to an object. The Object Spy displays the selected object’s hierarchy tree and its properties and values in the Properties tab of the Object Spy dialog box.
- From menu bar icon as shown below
- Tools -> Object Spy
- Resources -> Object Repository Manager
- Resources -> Object Repository
Upon Clicking on the above navigation options, the Object Spy Dialog box opens.
Understand Object Spy UI –
Hand – This is the point where you can start my interaction with the objects, just click it and move hand over the required object and will provide you the run time object properties. Moreover you can press CTRL key to hide my hand to perform normal operations of mouse.
Highlight – This feature will be disabled until and unless no object is added to UI. One’s the object is added it will help you highlight that particular object in the application. (with a blink around that object)
Note: – Incase not able to find the object due to nonexistent of object or properties are not unique, It will generate an error message like below.
Add object to object repository – Using this feature you can add the selected object to object repository.
- Only the selected object from the hierarchy will be added to OR
- One’s that object is added to OR, this button will become disabled.
- Object will be added to local Object repository incase object spy launched from Local object repository or from menu bar icon or from tools options. object will add to shared OR only incase object spy launched from object repository manager.
Copy to clipboard – Click on this button to copy all the object properties in ,name:=value pair combination. Paste them in any of the editor to see all the properties.
Note:- This feature is important while working with descriptive programming in UFT, as you can utilize this properties in descriptive programming.
Keep me on Top while spying – You can keep me on the top of the application while hand button is active or make me invisible while object spy is active.
Object Repository(OR) Types –
Depending on the way objects are stored and used by UFT test script, Object repositories are divided in two types.
- Local Object Repository
- Shared Object Repository
Local Object Repository
In this type of repository, the objects are stored for a particular action and only that particular action can access the stored objects. As we know that UFT creates a New Test with 1 action by default. An action is nothing but few lines of code in the UFT Script. One script can contain multiple actions. If you are recording some operations on the application first you must choose in which action of the UFT script must be recorded. Local Object Repository can be opened by traversing to Resources → Object Repository. This is the default OR in QTP.
Shared Object Repository
A shared object repository contains objects that can be shared by multiple actions of the same test script or different test script. A shared object repository stores in the form of a file with extension .tsr which stands for test shared repository.
Local objects can be exported to be saved into Shared Object Repository by using the option “Export Local Objects” Options. Shared Object Repository can be opened by traversing to Resource → Object Repository Manager
Points to remember:-
- When a test is recorded objects are by default stored in local object repository.
- A test can use a combination of repository types. That is a test can use both local and shared repository together.
- If an object with the same name is located in both the local object repository and in a shared object repository, the action will use the local object repository.
- A test can be associate with many shared repositories.
- If same name object is located in more than one shared object repository, the object is used from the first occurrence of the object, according to the order in which the shared object repositories are associated with the action.
Object Repository as XML
Object Repository can be saved in XML format so that size of the Object repository is reduced. The Object Repository (OR) can be saved as XML by “Exporting as XML” from Shared object Repository Window as shown below :
The Same object repository can be imported from XML and can be edited/deleted and exported back to XML.
Navigation – Resources >Object Repository Manager > File > Export to XML
Object Repository Comparison Tool
The object repository comparison tool is used to compare two repositories for similarities and variations among the objects. This tool compares for different object names, descriptions(properties and values of each object) in the two repositories.
Merging Object Repositories
The object repository merge tool is used to merge two object repositories into a single repository.
- Go to object repository “Resources > Object Repository Manager”, In Object Repository Manager select Tools > Object Repository Merge Tool. The following new merge window will be opened
- Select the files that have to be merged
- Click OK. the Object Repository Merge tool automatically merges the selected object repositories into a new target object repository.
- Click close.