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
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.
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.
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.
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.
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.
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.
<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.
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.
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.
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.
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.
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.
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.
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
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.
_______________________________________
Please send your Suggestions and Doubts to my yahoo group http://in.groups.yahoo.com/group/qtpsudhakar
Very useful content...........
ReplyDeleteexplained very nicely.....
ReplyDeleteValuable info. Fortunate me I discovered your site by accident, and I'm shocked why this
ReplyDeleteaccident didn't happened in advance! I bookmarked it.