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

Tuesday 13 December 2011

QTP Environment Variables and or Objects

How Can I make a variable/Object environmentally available i.e. throughout execution?


QTP has Environment Object which has Execution wide or global scope.

To Store your variable.

Environment.Value("MyVariable") = "MyValue"

or you can write this way

Environment("MyVariable") = "MyValue"


To Access Variable Value

strValue = Environment.Value("MyVariable")

or

strValue = Environment("MyVariable")

Do you know apart from storing simple values (like String, integer etc ), we can also store objects like dictionary, array etc.

Suppose I have defined a Dictionary Object

Set oDic = CreateObject("Scripting.Dictionary")

Following are the key-values pair defined
oDic.Add "Key1", "Value1"
oDic.Add "Key2","Value2"


Now Somewhere in code, I will store this dictionary object in Environment.

Environment("MyDictionaryObj") = oDic


How will I access it now? Here it is . . .

MyValue1 = Environment("MyDictionaryObj")("Key1")

Now try to understand the above line, the Blue background will evaluate to Dictionary Object that we had stored. Now see below Debug viewer Window to make you visualize about these objects.


Similarly we can also store array
MyArray = Array("Pankaj", "Anand", "Hussain")
Environment("MyEnviroArray") = MyArray

So How will I retrieve the value, below screenshot is self explanatory.





This was all about the programmatic approach to play with Environment Object.
Now let's see what QTP has in Environment Object.

Well their are 2 types of QTP Environment object.
1. In built
2. User Defined

Under QTP IDE, go to file--> Settings

Now whatever environment variable we defined in code will be User Defined type of Environment Variables.

QTP has inbuilt defines Variables which can be leveraged in your code from Framework designing perspective like "TestDir", "TestName", "UserName" etc . . .
Below is the screenshot of debug viewer that is during run time this variables are also available

Now Talking about User Defined Variable
You can also define variable initially also. like this . . .



Now Below is the screenshot of "Test Settings" Window during Run Time.
All user defined variables can be seen in this window.
Can you see it? . . . Open your QTP- try it

And Last but not the least you can also take bunch of Environment variable in an XML file and import in QTP. Create XML file like below fig and then use import functionality which is available in File--> Settings window.


Below is the figure after importing XML based Environment Variables


So, go ahead and try it . . .
Have a great time.

-Pankaj Dhapola

Friday 9 December 2011

QTP - Why Analysis and Planning is important before you start with framework designing.

Of course everyone knows why planning is important.

Now The question is what shall I do for framework designing. What are the points do I need to remember while designing a framework?
Well well well . . .
Framework designing is not a simple thing where you learn this blog or learn material from internet and you start off with it. It require work experience in various framework, but this is not the end.

Their is a great saying I heard from one my close friend Srimaya Mahapatra
"Wise people are those who learn from their mistakes and Wisest people are those who learn from other's mistake."
Seems to be a powerful statement enough to change one's life.

Coming back to business . . .

Before you start designing a framework in QTP, below are the question you need to ask yourself.
1) Do I know the functionality of each module for AUT?
2) Do I know what are the input data into this application and what are the outputs?
3) What would be my design flow right from initialization of script to result display?
4) What kind of framework I shall use? Mostly people use hybrid one.
5) Whether to use DataTable or ADODB or both?
5) Whether to use OR or DP or both?
6) Whether to use Reporter object for reporting or Custom based results?
7) Whether to Multiple actions or Function library?
8) What kind of recovery scenario, error handling should I need to include?
9) How about synchronization?

All this question can only be answered by YOU.

To decide all these, you must have experience enough to understand usage of all these concepts.
It is advisable to go over these once, so that you could be familiar with these concepts.
It's long journey my frnds, but don't worry each journey would be refreshing. :)

I shall Go over these with an understanding where novice people can understand and people with astonishment will ask themselves "Oooooo! QTP aisa kaam karta hai kya!!!" i.e. Do really QTP work internally like this?

Thanks and Warm Regards
Pankaj Dhapola

Wednesday 7 December 2011

An insight into Object

Hi,
I am Pankaj Dhapola, I am Currently working as SW test automation engineer.
I intend to write this blog for novice people in the world of SW test Automation.

A little about programming.

For me programming is irrespective of Language unless and until you know 3 things
1. What you want to achieve by writing piece of code.
2. Are syntax clear with what language you use.
3. and the kind of logic you use to achieve your goal.

Well the best language that I came across is JAVA. Imagine the creation of object inside a compiler.
For those who think what the heck is Object? here it, basically in any programming language their are two things
Object data and Object methods.
Now Object data is data\properties\attributes related to Object and Object methods are functions\actions\bundled of code which can interact with other object\environment and also are ways to read or modify data related to object.

example consider I create an Object called Man
Now data related to object would be
like
int NoOfHand
int NoOfFingers
String NameOfMan

and methods inside an Object Man would be

getLegsCount()
getNoOfFingersInLegs()
getNameOfMan()
ableToRun()
run()
runFast()


So, you decide, while programming what method and data of Object you would define.
Also what the data and methods available while you use an inbuilt Object.
For detailed understanding click here

I admire Java because its a very disciplined language, their is no way you can illegally exploit an Object. For every thing, their is a strict law\rule  to access object, m talking about the internal architecture of compiler.

Also VB script is a beautiful,  of course every language has its own pro's and con's.
BTW VB  is not an OOP's based language, it's Object based language that means you will be provided various objects\libraries bundled, you just have to use them.

I end this blog with these note and shall come up with many new things.