Skip to main content

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"

Comments

Popular posts from this blog

JMeter Exceeded Maximum Number of Redirects Error Solution

While running performance test, JMeter allows maximum 5 redirects by default. However, if your system demands more than 5 redirects, it may result in JMeter exceeded maximum number of redirects error. In this post, we have listed down steps to overcome this error. Actual error in JMeter: Response code: “Non HTTP response code: java.io.IOException” Response message: “Non HTTP response message: Exceeded maximum number of redirects: 5” This error is noticed because  JMeter  allows maximum 5 redirects by default and your system may be using more than 5 redirects. You need to increase this count to more than 5 in jmeter.properties file. Follow below steps to achieve this. Navigate to /bin directory of your JMeter installation. Locate jmeter.properties file and open it in any editor. Search for “httpsampler.max_redirects” property in opened file. Uncomment the above property by removing # before it. Change to value to more than 5 Eg. 20. Save the file and restart JMeter. If

SSO with SAML login scenario in JMeter

SAML(Security Assertion Markup Language) is increasingly being used to perform single sign-on(SSO) operations. As WikiPedia puts it, SAML is an XML-based open standard data format for exchanging authentication and authorization data between parties, in particular, between an identity provider and a service provider. With the rise in use of SAML in web applications, we may need to handle this in JMeter. This step-by-step tutorial shows SAML JMeter scenario to perform login operation. First request from JMeter is a GET request to fetch Login page. We need to fetch two values ‘SAMLRequest’ and ‘RelayState’ from the Login page response data. We can do this by using  Regular Expression Extractor . These two values need to be sent in POST request to service provider. Refer below image to see how to do this. We will get an HTML login page as a response to the request sent in 1st step. We need to fetch values of some hidden elements to pass it in the next request. We can do this b

A Tutorial to Send Email using JMeter

Sending email is a mundane activity in any professional’s life. It’s a common medium for communication nowadays. Therefore performance testing of email server is not only important but necessary for an organization. JMeter can be helpful to perform load testing in such scenarios. In this tutorial, we will see how JMeter can be used to send email. We will use SMTP Sampler of JMeter to send an email. JavaMail API is needed to enable email functionality in JMeter. Download it from  here  and paste the jar in JMeter’s lib folder. Now, perform below steps to configure SMTP Sampler. Add a new Thread Group under Test Plan. Right click on Thread Group and select Add–>Sampler–>SMTP Sampler. We need to populate SMTP server’s details in this sampler. We will use GMail for sending an email. For this, enter these values in SMTP Sampler fields. Server: smtp.googlemail.com, Port: 587. Provide values in Email Address From and To fields of Mail Settings section to specify sender and reci