Facebook

Course Name Start Date Time Duration Registration Link
No Training Programs Scheduled ClickHere to Contact
Please mail To sudhakar@qtpsudhakar.com to Register for any training

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

3 comments :

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

    ReplyDelete
  2. explained very nicely.....

    ReplyDelete
  3. Valuable info. Fortunate me I discovered your site by accident, and I'm shocked why this
    accident didn't happened in advance! I bookmarked it.

    ReplyDelete