Facebook

What's New @ QTPSudhakar
*Recorded Session on New Features in UFT 11.5x by Sudhakar Kakunuri. Click Here to Watch.
New QTP Training Batches @ MindQ Systems by QtpSudhakar
WeekDays :
Starting from Sept 22nd 7.30AM to 9.00AM
Starting from Sept 22nd 10AM to 12PM
WeekEnd :
Starting from Sept 20 9.00AM to 2.00PM Click Here to Register.

Cracking the QTP interview - Paperback Book

A new book "Cracking the QTP interview" authored by Sudhakar Kakunuri. This book is a paperback and it was published by TATA McGrawHill. It consists of 400 frequently asked questions with detailed answers for all topics including QTPScripting and VBScripting. Also a framework explained with step by step and you can easily develop by following the steps provided in the book. A list of Framework expected Q&A's are provided... Read More
MRP: Rs.295/-

Buy This Book From
BookAdda
FlipKart BuyBooksIndia

Saturday, January 21, 2012

Web Object Identifiers in QTP


Web Object Identifiers in QTP

During a run session, QuickTest attempts to identify each object in your application by matching the description properties stored for the corresponding test object with the properties of the DOM element in the application. For complex Web applications that contain many objects, using only the standard identification methods may have unreliable results.
You can instruct QuickTest to use Web object identifiers before the regular object identification process to help limit the number of candidate objects to identify. QuickTest accesses the application's DOM and returns objects that match the object identifier property values. QuickTest then continues to identify this smaller set of returned objects using the normal object identification process. Therefore, using Web object identifiers can lead to a more reliable and accurate object identification, and a quicker object identification process.

Web Object Identifier Types

The following Web object identifiers are available:
CSS
CSS (Cascading Style Sheet) is a language used to define formatting of elements in HTML pages. You can define a CSS identification property value for a test object to help identify a Web object in your application based on its CSS definition.
QuickTest uses CSS identifiers only when identifying objects and not when learning objects. Therefore, they are not available from the Object Spy or the Object Identification dialog box.
User-defined XPath
XPath (XML Path) is a language used to define the structure of elements in XML documents. You can define an XPath identification property to help identify a Web object in your application based on its location in the hierarchy of elements in the Web page. Because of the flexible nature of the language, you can define the XPath according to the unique way your Web page is structured.
QuickTest uses XPath identifiers only when identifying objects and not when learning objects. Therefore, they are not available from the Object Spy or the Object Identification dialog box.
Automatic XPath
You can instruct QuickTest to automatically generate and store an XPath value when learning Web test objects. During the run session, if the automatically learned XPath for a particular object results in multiple matches or no matches, the learned XPath is ignored. Additionally, if you have added a user-defined XPath or CSS identification property to a test object description, then the automatically learned XPath is ignored.
Automatic XPath is a QuickTest-generated property, and therefore it is not available from the Object Spy, the Add/Remove Properties dialog box, or the Object Identification dialog box.
Attribute/* Notation
You can use the attribute/* notation to access custom native properties of Web-based objects or events associated with Web-based objects.

How to Use Web Object Identifiers - Exercise

In this exercise, you use XPath and CSS identifiers in a test object description to help locate the correct button in an HTML table.
1.       Prerequisites
a.       Open QuickTest and create a new test.
b.      Disable Smart Identification for the Button test object class by selecting Tools > Object Identification, selecting the Web environment in the Object Identification dialog box, and then selecting the Button test object class from the Test Object classes list.
c.       Disable automatic XPath by selecting Tools > Options > Web > Advanced, and then making sure that the Learn and run using automatic XPath identifiers checkbox is not selected.
2.       Create a sample Web application
a.       Copy the following syntax content into a text document, and save the document with an .html extension. The document is saved as an HTML page.
<html>
<head>
<style type="text/css">
body { background: green; color: blue; }
.SelectedRow { color: #22444; background: #ebcbeb; width: 450px; }
.RegularRow { color: #444; background: #cbebeb; width: 450px; }
.BPTRow { color: #D9660E; background: #cbebeb; width: 450px; }
</style>
</head>
<body>
<br><br>
<table onclick="javascript:change();" id="maintab">

<tr class="BPTRow" id=BPT>
<td> HP Business Process Testing </td>
<td> <input type="button" value="Buy"> </td>
</tr>

<tr class="RegularRow" id=QC>
<td> HP Quality Center </td>
<td> <input type="button" value="Buy"> </td>
</tr>

<tr class="SelectedRow" id=QTP>
<td > HP QuickTest Professional </td>
<td> <input type="button" value="Buy"> </td>
</tr>

</table>
</body
</html>
b.      Review the appearance and content of your newly created HTML page in any browser. Make sure that it matches the following image.
3.       Learn the button objects in the Web application
a.       In QuickTest, open the Object Repository Manager, and select Object > Navigate and Learn. QuickTest is hidden, and the cursor changes to a pointing hand.
b.      To verify that QuickTest learned the objects correctly, in the object repository, select each Button object and select View > Highlight in Application. QuickTest highlights each button object in the HTML page.
c.       Rename the Button objects to make them more clear:
§  Rename Buy to Buy_BPT.
§  Rename Buy_2 to Buy_QC.
§  Rename Buy_3 to Buy_QTP.
4.       Remove the ordinal identifiers from the button objects
Because all of the Button objects have identical property values, when QuickTest learned the objects it assigned an ordinal identifier to each test object based on the location of each object in the application. This may cause QuickTest to identify the objects incorrectly if the sorting order of the buttons in the application changes.
a.       Select the first button object to display its object properties on the right side of the object repository window.
b.      In the Ordinal Identifier section, select the Browse button. The Ordinal Identifier dialog box opens.
c.       In the Identifier type drop-down list, select None and close the dialog box. The ordinal identifier is removed from the test object's identification properties.
d.      Repeat steps a - c above for each of the buttons.
e.      Verify that the test object descriptions are no longer unique by selecting each test object and selecting View > Highlight in Application. QuickTest cannot identify the objects.
5.       Add a CSS identifier based on the object's parent-container
a.       Select the Buy_BPT button. The test object details are displayed on the right side of the object repository window.
b.      In the Object Description section, click the Add button, and add the css property to the test object description.
c.       Copy and paste the following syntax into the Value edit box:
tr.BPTRow input
6.       Add an XPath identifier based on the object's parent-container
a.       Select the Buy_QTP button. The test object details are displayed on the right side of the object repository window.
b.      In the Object Description section, click the Add button, and add the xpath property to the test object description.
c.       Copy and paste the following syntax into the Value edit box:
//TR[@id='QTP']/*/INPUT

a.       Select the Buy_QC button. The test object details are displayed on the right side of the object repository window.
b.      In the Object Description section, click the Add button, and add the xpath property to the test object description.
c.       Copy and paste the following syntax into the Value edit box:
//td[contains(concat(' ',text(),' '),'Quality')]/../*/INPUT
8.       Results
Select each object and select View > Highlight in Application. QuickTest can now identify each button based on the Web object identifiers you added.

 

Considerations for Working with Web Object Identifiers

General:
  • Defining xpath and css properties using Frame HTML tags is not supported. This may cause incorrect identification when identifying Frame objects or retrieving Frame objects using the ChildObjects method.
  • xpath and css properties are not supported for .NET Web Forms test objects or for other Web-based test objects that have .NET Web Forms parent test objects.
  • When running in Maintenance Mode, QuickTest may replace test objects with XPath or CSS identifier property values with new objects from your application.
Workaround: Use the Update from Application option in the Object Repository Manager to update specific test objects with XPath or CSS identifier property values.

Differences Between User-defined XPath and Automatic XPath Behavior During Run Sessions

Behavior in case of...
User-defined XPath
Automatic XPath
Multiple objects match the XPath value
QuickTest continues to identify the matching objects.
QuickTest ignores the learned XPath and continues with the regular object identification process.
No objects match the XPath value
Object identification fails, and QuickTest continues to identify the object using Smart Identification
QuickTest ignores the learned XPath and continues with the regular object identification process.

Accessing Custom Properties of Web-Based Objects

You can use the attribute/* notation to access custom native properties of Web-based objects or events associated with Web-based objects. You can then use these properties or events to identify such objects by adding the notation to the object's description properties using the Object Identification dialog box, or by using programmatic descriptions.
Example of using attribute/<property> to identify a Web object
Suppose a Web page has the same company logo image in two places on the page:
<IMG src="logo.gif" LogoID="122">
<IMG src="logo.gif" LogoID="123">
You could identify the image that you want to click by adding the attribute/LogoID notation to the object's description properties and using a programmatic description to identify the object:
Browser("Mercury Tours").Page("Find Flights").Image("src:=logo.gif","attribute/LogoID:=123").Click 68, 12

Suppose a Web page has an object with an onclick event attached to it:
`'alert('OnClick event for edit.');"
You can identify the object by adding the attribute/onclick notation to the object's description properties and using a programmatic description to identify the object:
Browser("Simple controls").Page("Simple controls").WebEdit("attribute/onclick:= alert\('OnClick event for edit\.'\);").Set "EditText"
_______________________________________
Please send your Suggestions and Doubts to my yahoo group http://in.groups.yahoo.com/group/qtpsudhakar

2 comments:

  1. Very useful content...........

    ReplyDelete
  2. explained very nicely.....

    ReplyDelete

All Posts

Show all Object properties without using Object Spy | Deleting Browsing History, Temporary Files, Cookies | How to click on all Google Search Links in all Pages | How to click on all Google Search Links in a Page | VB Script Samples | Working with Recovery Scenarios using Scripting | Virtual Objects in QTP | Diffrent ways to write a statement | Synchronization | Object Identification in QTP | Test Object Model in QTP | Object Repository Types | Managing Object Repositories Using Object Repository Manager | Recording types in QTP | Using Dictionary Objects In QTP | Working with Webtable Object | Descriptive Programming in QTP | Regular Expression for Date and time | Get Runtime Object Properties for a web Object | Get Test Object Properties | Using RunTime Object Properties in QTP | Component, Distributed Component, Automation and Document | QTP Scripting Sample Questions | Advanced VB Script Questions | QTP Version Information Card | WSH Scripting Samples | Working with links Using DOM | File System Object | ListBox Object | Menu Object
Automation Object Model | QTP Tips | How to take screenshot using VBScript? | QTP Scripts Upgrade Tool | Delete Cookies using QTP | How to export/copy KeyWord View Documentation? | Activating a opened window or Browser | VBScript Basics | How to close a windows process through QTP? | How to return multiple values from a function? | What is the limitation of capture screenshot in QTP? | Compare Two bitmaps using QTP | How to update a particulare line in a text file? | Locking and Unlocking Machine in Script Runtime | How to capture the tooltip of a link? | Add and Remove Repositories to an Action In RunTime | When we have to use Update Run Mode? | Use of INI File in QTP | How to Run the analog recorded code which is copied from another test? | What is the maximum size of an Object Repository? | How many action can we create in a single test? | How to connect to SQL without DSN? | What is the use of INI File in QTP? | How to test Slideslow in a page? | How to write DP for an object having many objects in its heirarchy? | How to Convert a number to Currency Format? | how to parameterize links in a web page? | How to Accessing Windows API through vbs? | Advanced VB Script Samples | Executing QTP Scripts on a Remote Computer
Get Objects from Object Repository | Test / Action Iterations | QTP Environment Support Card | Read CSV File Data | Regular Expressions in VBScript | Creating Comments and Action Template | Import CSV File Data in to QTP Datatable | Sample DOM Script On Google Search | Regular Expression in QTP | Sample Script on Descriptive Programming | Object Hierarchies in QTP | Working with Existing Browser Using DOM | Find Hidden Rows in a Table | Preparing and Using Test Data for Automation Test Scenarios | Close latest opened Browser using QTP | Working with Data Table Utility Object | Check whether QTP script is Opened in Read Only Mode? | Quality Center Practice Assignments | All about Validation of Editbox – Part-1 | The Concept of Keyword Driven Framework | How to find Data Type of a Variable? | How to click on dupllicate links in a WebTable? | Difference between Index and Location | All about Validation of Editbox – Part-2 | Click on Object by Holding CTRL Key | Selecting an Environment to Execute Scripts | Descriptive Programming for Virtual Objects | Set Value in EditBox Using DOM | Data-Driven and Keyword-Driven Test Automation Frameworks | Using one Library Functions / Variables in other Library | Features of Object Repository Window and Object Repository Manager | Common DOM Methods & Properties | VBScript Features | Scripting Page Checkpoint