How QTP Identify Object Uniquely? – This is the 7th QTP Tutorial in our QTP training series.
We are getting ourselves equipped with all the basic concepts that will enable us to write robust QTP tests. We have covered the QTP Record and Run settings, Working with Keyword view and the other related topics.
This is the next article in the series that talks about a crucial aspect of QTP – The mechanism it uses to identify an object uniquely. When you look at the below screen:
There are 3 buttons and 2 text boxes along with various other elements in this dialog.
In the previous examples, when we entered the username and password we saw how QTP recorded the same operations in terms of programmatic code as well as a table in keyword view. Now, during playback how does QTP know that the value we provide as Agent Name or Password has to go respectively in those edit boxes. Or how does it know which button to click to submit the values entered?
Let us try to find an answer to that.
It is clear that QTP somehow remembers which object to act on. The way it does it is, it stores the object in the AUT as a test object. It then examines its properties and classifies the object. For Example, when it encounters the OK button it examines its properties and based on these, it classifies the object as a ‘WinButton’.
QTP has a predetermined set of properties that it learns/stores for every class of object it identifies. There are 3 aspects to this:
- Mandatory properties: This is the list of properties for a certain class that QTP always stores. We could say that this is the object description. It also checks this in conjunction with the parent object to see if the description is sufficient to identify the object uniquely.
- Assistive properties: In case the description of mandatory properties is insufficient to identify the Object a set of non-mandatory properties will be added to the description one after the other until there is enough data to identify the object.
- Ordinal Identifier: If the assistive properties also do not result in a unique identification of an object a special ordinal identifier is added by QTP, such as the object's location on the page or in the source code.
So, this is how QTP forms Test Objects. It uses this Test Object description to search for the objects to act on during a run session. It chooses the objects that match perfectly with the description it contains. These objects are called Run-Time objects.
Unless your application has changed significantly the Test Object description that QTP has is sufficient to find an object.
For the WinButton object that we have in our Flight app, let us see what properties QTP has stored. This information is available in the Object Repository. The menu option “Resources->Object Repository” will launch the OR for us. Alternately, you can use CTRL+R or click on the icon.
If you notice in the above window, it stored the ‘text’ in the WinButton as its description to identify this button at runtime.
For more complicated applications, the tester can add or remove certain properties to make the description robust enough to identify the object at runtime more precisely. To do this, simply click on the ‘+’ icon.
All the other properties of the object will be displayed. The user can choose to add one or more of these properties.
There is also something called “Visual Relation Identifier” in the OR screen for the WinButton properties.
This is a feature that further supports object recognition according to their neighboring objects in the AUT. Once set, this creates a kind of link for the less stable components in your AUT with the objects that are more uniquely identifiable. QTP will identify these objects as long as they maintain their relative position to these unique objects.
To set a kind of positional link we are going to have to click on this column in the OR and the following screen comes up:
In this screen select the ‘+’ sign to add an object with which you want your test object to having a positional link.
I will choose “Agent Name” and say that this object should be above the “OK” button.
This is how I set that:
Now, in case some properties of OK button changes in the future, QTP will identify it if, “Agent Name” is above it.
This is the mechanism employed by QTP under one of these two situations. The description for an object that QTP has:
- Does not match with any runtime objects
- Matches with multiple objects
This is a little bit of an advanced concept, so we will get to it at a later time via some examples for easy and elaborate understanding.
This is a numeric value that depicts the relative order of the object with objects that have a similar description. If an object 1 and Object 2 have the same mandatory and assistive properties, then the ordinal identifier will be used to recognize the object uniquely.
This value is related to the other objects of the screen, so in case anything changes in the screen, this identifier might not come useful. It should be noted that, if the mandatory and assistive properties are enough then an ordinal identifier is not assigned to record. It can be added later on by clicking on the respective column for the object in the OR
There are 3 kinds of Ordinal Identifiers:
- Index: this is based on the order of appearance of an object in the application code
- Location: based on the location in a screen or dialog or page
- Creation Time: This is used only for browser objects. In case 2 browsers with similar properties exist, then the one that is created first and next is considered.
For Example, let us understand how the ‘index’ identifier works in our Flight applications login screen:
These are the following components:
As you can see, the static text and the edit boxes have the same ‘text’ property.
If I know that one of them is a static text and the other is WinEdit object, then there is no problem at all. Say if all these are treated as WinObject then I will have to specify which object to act on. This is only going to happen when the mandatory, assistive and smart identification has failed. So in order to tell QTP which is what, I am going to assign an ‘Index’ ordinal identifier. I will do so from the OR.
I will set the Agent name static text identifier as 0 and for the edit box, I will set it as 1.
This is how it looks:
So if I need to access the static text then I will do so as follows:
WinObject(“text:=Agent Name:”, index:=0) – This will refer to the static text
WinObject(“text:=Agent Name:”, index:=1) – This will refer to Edit box
The same theory applies to the Location identifier too except that we will choose the location in the window to determine the numeric value that is applicable to a certain object.
Configuring Object Identification properties:
The mandatory, assistive properties and ordinal identifiers to be considered for an object of a certain class to be recognized can be configured by using “Tools->Object Identifier”. We can also set the smart identification properties through this window.
The window looks as follows:
As can be seen in this above image, the environment can be chosen from the drop-down box. Once that is chosen the classes of objects in the corresponding environments are shown in the list. After an object is selected, the mandatory and assistive properties are displayed. The user can Add/Remove additional properties to this list.
Also, smart identification can be enabled/disabled for a certain class of objects when needed. To set the ordinal identifier there is a drop-down that can be chosen to identify the object using Location, Index or Creation Time (only for browser type only).
We will wrap up the fundamental concepts before moving on to full-fledged QTP programs. The next QTP article will have different recording modes, Object Spy, Object Repository, etc. details.