Monday 19 December 2011

QTP object identification process

How does QTP identify an object?

Well being a technical guy this question has been wondering me a lot before knowing it.

When I learned that QTP identify objects on the basis of properties and I was knowing that each and every object in DOM or Web Page has been assigned with properties (attributes) and its values. So I went into flashback when I used to create HTML pages . . .
For each web element frame, form, button, text box etc we assigned properties/attributes and value inside tags, u remember?
something like below figure . . .

Notice the tags and the attributes that html dveloper have assigned to each object in the html page.

These are the properties that QTP leverage to Identify a particular object.













This would be very interesting afterwards.


Let's go into some theory,
To be very specific QTP has grouped properties under 3 categories
1) Mandatory(or base) Properties:- These are most important properties which are required to identify
objects.
Example:- In a WebPage, how come a particular object is identified as button or textbox? its because of its mandatory property like object type of Class Name, whether it is WebButton or WebEdit. 

Note that:- sometimes it is possible to identify object without this property.

2) Assistive Properties: - Sometimes Mandatory property is not enough to identify an object uniquely, so
this property is used. Hence the name is given Assistive. example:- name, text, value etc

3) Ordinal identifiers:-    If above both fails then ordinal identifier are used to identify object. These are
like  Location and index (or order) of object.


"Now don't ask me how QTP extract the properties from application. That shall be another blog."


QTP identification process works exactly same as human like filtration process. Now to understand this you will have to think like a machine or AI. 


Example:- You might have seen Rajnikant's Robot movie right? 
Now suppose you have a family photo of Aishwarya Rai and you ask Chitti (the Robot) to Identify Sana (Aishwarya) from this photo. Now what does Chitti do?

He opens up his informational database regarding Sana and list out all properties or features.
Now he scan the photo and in first step process he figure it out the their are 2 males and 2 females. Now according to his informational database Sana is Female, so he filter out 2 males from photo and concentrate on 2 female. Here the property "female" is Mandatory or base filter property.  ok?

In the next step process he identifies that skin color which turn out to be same for both female, here the assistive property "skincolor" is not enough but again look for next property like Age.
This time he figure out that his informational database age and the visible age in photo and filter out the other women and uniquely identify Sana from the photo using assistive property "Age".

In this way objects are filtered out on the basis of Object properties.

Sometimes it may happen that due to lack of above two types of unique property Chitti fails to identify Sana. Now this time he uses the ordinal identifier property like location. for example, he scan his whole image database and finds that Sana Always stand on left hand side of photo in a group of 4. So he assumes that in this photo also she might have been standing in extreme left and says "Person in extreme right is Sana".

Now you might ask me so why QTP uses Mandatory and Assistive property then, why not use Ordinal directly? Suppose in other photo Aishwarya stands in the middle instead or extreme left, now chitti fail to identify Sana. That's why I mentioned the word "Assumes" and Chitti said  "Person in extreme right is Sana", he did not even said female on extreme left. Ordinal Identifier are not the reliable properties to Identify Objects many a times.

Their is Concept call Smart Identification feature- Sometimes what happens is while identifying objects QTP lacks exact property of object, so in this case QTP assumes that which object is very much near to the exact property provided. Not much to talk on this.

Their an inbuilt tool called Object Spy which is available in QTP menu with this Icon.
Object spy look like a window having properties and values column with a button having image of hand point to left.








Coming back to my flashback's HTML page and its code, I went home and searched out that HTML page and place the Object spy hand in it. I was surprised to see the properties in Object Spy of the WebEdit that I had created.

Below is the screenshot with marking.


Isn't this amazing? Are you actually able to relate things properly? Give a close look at the red and blue boxes.


Try it now!!! 
-Pankaj Dhapola