QTP Tutorial #7 – QTP’s Object Identification Paradigm – How QTP Identify Objects Uniquely?

By Vijay

By Vijay

I'm Vijay, and I've been working on this blog for the past 20+ years! I’ve been in the IT industry for more than 20 years now. I completed my graduation in B.E. Computer Science from a reputed Pune university and then started my career in…

Learn about our editorial policies.
Updated October 11, 2024

How Does 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.

=> Click Here For QTP Training Tutorials Series

Object Identification Paradigm

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.

QTP login dialog

How Does QTP Identify Object Uniquely

When you look at the screen above, 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 do you know which button to click to submit the values entered?

Let us try to find the 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 objects to act on during a run session. It chooses objects that match perfectly with the description it contains. These objects are called Run-Time objects.

Unless your application has significantly changed 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.

QTP Object Repository

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.

QTO Object Properties

All 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 click on this column in the OR and the following screen will come up.

QTP Visual Relation Identifier

On this screen, select the ‘+’ sign to add an object with which you want your test object to have a positional link.

I will choose “Agent Name” and say that this object should be above the “OK” button.

This is how I set it up:

QTP Visual Relation Identifier 2

Now, in case some properties of the OK button change in the future, then QTP will identify it if, the “Agent Name” is above it.

Smart Identification

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 elaborative understanding.

Ordinal Identifier

This is a numeric value that depicts the relative order of the object with objects that have a similar description. If 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, then 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 on the screen, 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 the next is considered.

For Example, let us understand how the ‘index’ identifier works in our Flight applications login screen:

These are the following components:

QTP Test objects

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 a 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 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 OR.

QTP Ordinal Identifier

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:

QTP Object properties

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 up smart identification properties through this window.

The window looks as follows:

QTP Configuring Object identification properties

As seen in the 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. in detail.

=> Visit Here For The QTP Training Tutorials Series

Was this helpful?

Thanks for your feedback!

Recommended Reading

  • QTP Tutorials

    Today we are publishing part one of a multi-part guest post series on Micro Focus Quick Test Professional (QTP). In this multi-part QTP training series we'll be covering all QTP tutorials and concepts in detail with adequate illustrations. Our expert author Swati S. will be helping us in bringing this…

  • Object Repository

    Object Repositories in QTP and Object Repository Manager This tutorial will focus on QTP Object Repositories. In our previous articles, we have discussed how QTP identifies and stores objects in a warehouse, the OR. We have also seen how the object properties appear in the OR. To quickly recap, we…

  • Using Virtual Objects and Recovery Scenarios

    Do you see an object not found error while running QTP tests? Well, this is because, during playback, QTP can’t recognize non-standard objects. To solve this object recognition problem, we use Virtual Objects. Using Virtual Object Wizard we can map these unrecognized objects to a standard class which can then…

  • QTP Test Result Analysis

    In this QTP tutorial, we will learn - Smart Object identification, adding Synchronization point, Running a test & viewing the results, and the Silent Test runner. => Click Here For The QTP Training Tutorials Series Assume a situation when no object matches or multiple objects match the recorded description for an…

  • Object Repositories

    In this tutorial, we will talk about the different recording modes, Object Spy, and Object repositories in QTP. => Click Here For The QTP Training Tutorials Series Recording Modes in QTP Recording is the most commonly used method to create a test. The basic steps are typically recorded and the test…

  • Techniques for Parameterization

    In part 1 of this QTP Parameterization tutorial, we explained Datatable Parameterization with an example. In this QTP tutorial let’s focus on the remaining three Techniques for parameterization in QTP: 2) Random number parameters 3) Environment variable parameters 4) Test/Action parameters => Click Here For QTP Training Tutorials Series #2 -…

  • Parameterization in QTP

    What is QTP Parameterization? Sometimes the application does not accept duplicate data records. In this case, if you run the same Test script with a fixed set of input data, an application may throw an error due to data duplication. To avoid this issue, QTP provides ways to accept different…

  • Using Text Area, Table, and Page Checkpoints

    In the last article, we were discussing the ways in which QTP can compare text. We also saw how standard checkpoints can be used to check the text and discussed the text checkpoint in detail. The next checkpoint is the Text area checkpoint. Let’s begin exploring it. => Click Here For…


18 thoughts on “QTP Tutorial #7 – QTP’s Object Identification Paradigm – How QTP Identify Objects Uniquely?”

  1. @Suresh: Yes, there are various ways in which you can make QTP identify and act on an object. You could use Virtual objects or you can use descriptive programming. Both these topics are going to be discussed in the future sessions

    Reply
  2. Hi,
    I am new to QTP.
    Why below code is not working? I am trying to pass the pageName dynamically
    Browser(“Browser”).Navigate linkURL
    pageName = Browser(“Browser”).Page(“micclass:=Page”).GetROproperty( “title” )
    Browser(“Browser”).Page(pageName).WebEdit(“Write something…”).set(msg)
    Browser(“Browser”).Page(pageName).WebButton(“Post”).Click
    Please help me on this!

    Reply
  3. Hi Sriram,
    If QTP can’t determine a object from repository, when running a test, with smart Ident. QTP try to find a correspondenting object. So smart identification is useful when you create test, but it needs performance.
    Hope it helps.

    Reply
  4. @kiran: Try to spy the object whose index you want to find out during run time. location Ordinal identifier is the property you are looking for.

    Reply

Leave a Comment