Skip to main content

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.

Comments

Popular posts from this blog

Change IE Browser ZOOM settings

Lot of UI automation testers could have faced this problem as we could change the zoom settings while operating manually for our convenience and forgot to reset to 100%.
But our QTP and some other related tools would operate the browser perfectly if browser zoom is 100%. So wee need to change the zoom before start to run the scripts. Its better to have a code snippet in our framework to change this zoom setting right?
Here we go...

1. We can simply change the Registry values before Invoking IE
Function ChangeRegistry Dim objShell Set objShell = CreateObject("WScript.Shell")  objShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Zoom\ZoomFactor", "100000", "REG_DWORD" Set objShell = Nothing EndFunction This option is very useful. But in real time, lot of customers could have restricted write access to windows registry. So we can try other options.

2. Use IE COM object and Change Settings
Function ChangeIEZoom Dim intZoomLevel, objIE  intZoo…

QTP - Object Identification - Prerequesties

While starting a new project or proof of concept or after new QTP installation, we would face the issue in identifying objects as QTP built objects like WinList, WebEdit, etc.; instead everything will be identified as WinObject.

Here are some steps to ensure you did the environment setup RIGHT before start automating.
Did you enabled required Add-ins only while launchingDid you selected "Record >> Record and Run Settings" - This should be based on what type of application you are working with
Windows app - Windows >> Record and run test on any windows applications. Web app - Web >> Record and run test on any open browser.
Did you tried to launch UFT/QTP and then AUT.If its web, ensure browser zoom level set to 100%Try disabling the protected mode in IE for web.Launch UFT and AUT using RUN AS ADMINISTRATORAlso see the Object Identification Methods if you are interested.

Run JavaScript from QTP

Yeah, You can run your pure JavaScript from QTP using RunScript method. Lot of times, we are in need of firing events or simulating actions on web page which is not supported by QTP. At that time, you can use your direct DOM methods and directly execute your script on the web page from QTP like,
Dim MyPage, SearchBox Set MyPage = Browser("title:=Google").Page("title:=Google") Set SearchBox = MyPage.RunScript("document.getElementsByName('q')(0);") SearchBox.Value="testing"
'if objects available in frames, Set SearchBox = MyPage.RunScript("document.frames(4).document.getElementsByName('q')(0);")
'OR
Set objFrame = Browser("title:=Google").Page("title:=Google").Frame("title:=something")
objFrame.RunScript("document.getElementsByName('q')(0);") Also, you can execute by obtaining actual browser window object if you have IE app like, Dim IEApp Set IEApp = CreateObject("Internet…