Showing posts with label Object Spy. Show all posts
Showing posts with label Object Spy. Show all posts

Sunday, 8 January 2012

Object Repository in QTP

Wooah!!! Let get into deep understanding of Object Repository (OR in Short)

As the name suggest "A place where Object is stored", but don't get confused. Object in QTP world is basically "PropertyName-PropertyValue" pair. QTP Object Repository is a Graphical representation Various Test Objects and their properties along with hierarchical relationship with other objects as well.

Their are some more functionality available in Object Repository window like . . .
 Add Objects to Repository
 Object Spy
 Associate Other Repository from file
 Highlight Selected Test Object in Application

These are very few enlisted above with Icon Image.

Now lets see how does an Object Repository GUI window looks like.

Left Pane shows the total Test Objects what is going be used by QTP during Test Run. Now these object can be added manually or by QTP itself while recording a script rather I should say a workflow.
Two thing keep in mind to get familiarize with OR.
1) Notice the hierarchical relationships among objects. People who can understand HTML DOM (Document Object Model) can easily figure out why these objects are placed in such order.
2) Notice the Icon and Name of each Object.

Right Pane shows an Object properties and its values.

Lets take an example of our Test Object having Name "Google Search"
Notice the Icon, its a WebButton and the name "Google Search" 
Look at the Right Pane now 3 Description properties are displayed like type, name and html tag.
QTP have itself added these 3 properties to uniquely identify a particular object in application.

Now you will ask me what do you mean "QTP has itself added these properties"? (Note that I am talking about object properties and not Object because I have manually added all those objects in OR, but QTP have itself added all the required properties of each object.)

When I click on Icon         QTP vanishes and Object Spy Hand  appears and placed on the object (Google Search Button) then QTP fetch all the available object properties from the application and using Object Identification Mechanism it filters out that it require above 3 properties to uniquely identify Google Search Button in Google landing page. 

QTP self assign a name ("Google Search") to Google Search button object so that automation tester can use this name as reference in his code.
Now let's around with this object, 
1. Click on highlight button  and then Google Search Button gets highlight
2. Delete  some property and see that whether you can identify (or highlight) object, I deleted property "html tag" and guess what I was able to highlight Google Search Button. And I again deleted property "type" and I was able to highlight Google Search Button. And I again deleted property "name" and guess what QTP showed me 

What did I concluded here.
QTP sometimes take extra precaution to uniquely identify object hence add some more properties without which it can still identify object uniquely.
I have learned that the more number of properties you add, QTP will take more time to analyze object. Hence I started deleting properties.

Okay pals try yourself . . .
Happy Learning . . . :)

-Pankaj Dhapola



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