My Blog List

Sunday, August 26, 2012

QTP - Object Identification Types / Ways

In QTP, we can use lot of ways to identify an object. Most of the QTP Test Developers are always using streamlined and static approaches and if object is not identifiable using those approaches, just leaving then as not identifiable.
We can try using below ways of handling objects for our purpose before saying NO !!!

1. Store the objects in OR
If you are comfortable on using OR and suitable for your project with your designed framework, you can go ahead with OR.
a. Add the object in OR, then see what are the properties will make QTP to identify this object uniquely. 
b. Remove unwanted properties
c. Add unique and required properties
d. Assign regular expressions for the required properties which have dynamic values in full or part.Make use of Reg Exp Evaluator to set the RegExp correctly.
e. Assign a human understandable, easily classifiable logical name for the object based on type of object, application module or screen, etc.

2. Use Descriptive Programming
Here you can use 2 types of DP.
1. Inline or String DP:
Mention your properties in the line where we are mentioning our actions to be performed using name:=value pairs. 
Here the important point is, this type of object identification is regular expression support enabled by default. So you have to use literal character(\) if any regexp chars available as part of your name:=value pairs.
2.Description Object:
If you have lot of properties to instruct QTP to identify an object, inline DP will create lengthy statement and confusion. At this point, you can go with Description Object.
Create an instance of Description object and assign the values for all the required properties. Also you need to assign RegularExpression property true/false to enable the regexp support for the assigned properties.

3. Xpath
From QTP 11, you are ready to use xpath for web objects. Really its an easy way to inform the web objects path to QTP as like our normal DP.
Ex. To get the google search box
Browser("title:=.*google.*").Page("title:=.*google.*").WebEdit("xpath:=//INPUT[@name='q']").Set "testing"
Refer XPATH.

4. CSS Path
This also supported from QTP 11 like xpath.
Ex.To get the google search box
Browser("title:=.*google.*").Page("title:=.*google.*").WebEdit("css:=INPUT[name='q']").Set "testing"
Refer CSS Path.

5. DOM Path
This one you can use from previous versions of QTP. This is a method where we are directly fetching our objects from web page document using DOM.
In QTP, they have provided a function called RunScript and RunScriptFromFile for PAGE objects to execute the scripts on the page to get the objects.
You can make use of IE developer tools(press F12 to open in IE) to check and develop your DOM scripts.
Ex.To get the google search box
Browser("title:=.*google.*").Page("title:=.*google.*").RunScript("document.getElementsByName('q')(0)").value = "testing"
Refer QTP RunScript.

6. Virtual Objects
This is a known way to all QTP test developers. Just we are creating an image of our object and instructing QTP to identify runtime object based on the image.
Here you need to take extra care with respect to different environments, themes and also need to place the virtual objects folder to all QTP machines. 
This feature is used rarely by QTP developers worldwide but based on this type of image recognition, we have lot of automation tools in current world.

7. Virtual Relation Identifier
From QTP 11, we have an option to instruct QTP to identify the objects as manual testers are doing in real time by seeing visually using eyes. i.e. We can instruct QTP like,
a. Click the button which is available next to an identifiable button/element in horizonally.
b. Click the button which is available next to an identifiable button/element in vertically.
c. Click the button which is available before to an identifiable button/element in horizonally.
d. Click the button which is available before to an identifiable button/element in vertically.


You can instruct these properties in Object Repository itself for Visual Relation property.
Also, we can instruct this type of visual relation in programmatic way using Descriptive Programming without using Object Repository.

8. Create Custom Add-Ins
Create custom Add-Ins? What? Can we create add-ins ourself?
Yeah !!! QTP 11 provides an tool/utility called QTP Extensibility Accelerator to create custom add-ins for the custom objects support in your AUT.
Currently, QTP 11 provides a add-in creation template for Web Objects only. We can create our custom add-in with in 10 mins. But for other environments, you need to create using some IDE, need some basic VB or other coding knowledge. But we can create custom add-ins for all type of objects using this tool.
We will see a separate topic for this add-in creation later here.

Sunday, August 19, 2012

QTP - Common error messages

Always I am seeing  many of my friends asking for help if any error occurs while running script in QTP without googling for help. How much troubleshooting you guys are doing will directly reflect your knowledge on the tool. I agree, no one knows each and every error occurs in the software. But we can improve our knowledge by googling and doing workarounds...
Whenever the question "How much level you know QTP?" arrows me, always I am comfortable with the answer "below 10%". But after answered, my mind will have an inner thought like, What are the things I have to learn to fulfill the answer I have told because I never used lot of features in QTP.

Here I am listing out some of the errors, situations and what might be the original issue things etc. I hope this will give you some ideas to improve your debug ability and to solve your errors. Kindly correct me If I am wrong in any point.

Type mismatch:
- Mostly doing operations with different data types without doing type conversions
- Whenever the mentioned object or function not available in the code with respect to QTP knowledge. You might forgot to associate the function lib or renamed of the function.

Parameter is Incorrect:
- The data to be inserted or set in the object will have extra length. i.e. above the design limit of the test object.
Ex. Mostly while setting some value in edit box, we will get this error because we are trying to set the value with 50 chars in the edit box designed to handle max 30 chars.

UnExpected ):  
- Mostly fresh QTP coders will see this error. Whenever trying to call a function, use parenthesis only if you are going to get the returned value from the called function. 
- If you are not going to get the return value, then just mention your parameters without using ().

No. of parameters mismatch:
- Here you could have missed to mention all the parameters for your function.

More than 1 object is matching...:
- Here QTP identifies more than 1 object with the mentioned properties and got confused which one to handle. You need to give additional properties to identify your object uniquely. Sometimes index will give you hand.

Out of bound error:
- When you are trying to get the values from an array position which is not declared or assigned or not available.

Name undefined:
- You should have mentioned Option Explicit to force the variant declaration but you forgot to add the declaration for the variant.

Name redefined:
You should have mentioned Option Explicit to force the variant declaration but you declared the variant which is already declared.

Object Required:
Sometimes we will try to get an object from long hierarchy if its not identifiable easily. At this time, if any mid way object is failed in identification, QTP will throw this error.
Ex. While trying to get the object inside the WebTable, QTP will throw this error if webtable itself not identified.

General Run Error:
- Say you have function in your vbs file like Function abc(a,b) and from your test you are trying to call like If abc(a) Then. Here QTP will raise this type of error.
- And also some places where QTP not able to identify which type of error.

I will keep adding the errors I have faced and known to my knowledge. Definitely every one will face lot of errors. Kindly share the same here so that I will add those too for every one's reference.