Srinivas Aditya
Srinivas Aditya

Reputation: 91

QTP - In web-addin extensibility, Can I use custom attributes for object identification

We developed a custom add-in for QTP to automate an Extjs application. Recently we came to know that the approach we took to develop the add-in is unreliable. We used the CSS classes displayed in the DOM tree to help QTP identify each object in the ExtJS application. Recently our developer told us that this way of relying on CSS classes is a problem as these CSS classes keep changing. For Ex: In the ExtJS web application, the Login button control's DOM looks like this in the Browser(just an outline, not exactly like below)

<a class = x-btn x-box-item x-btn-default-small id=button-1086 unselectable = on style = margin>
     <span class = x-something>
         <span class = y-something>Login</span>

So, in the toolkit config xml for the custom addin, we wrote the identification for button like this

  <Conditions type="IdentifyIfPropMatch">
      <Condition prop_name="classname" expected_value="x-btn" is_reg_exp="true" />

We use Javascript to extract the label Login present in the span tag above and assign it to the title property of our custom Extjsbutton control. So when I record using QTP, the VBScript code generated is

         Browser("..").Page("..").Extjsbutton("Login").Click

In a recent release of the application, the button class name changed from x-btn to x-fastbutton in the DOM. With that QTP is not able to identify the button object.

We asked the application developer to give us some new attributes for each control in the application which are constant so that QTP can use them to identify each object in the application. The app developer gave us three new attributes and the new attributes look like this

  <a id = 'button-123', class = 'x-button' , uft-xtype = Button, uft-isComponent = true, 
      uft-extclass = Ext.button.Button>

My question is , can we use these new attributes and their values directly in the Condition element in the toolkit config xml like

   <Conditions type="IdentifyIfPropMatch">
      <Condition prop_name="uft-xtype" expected_value="button" is_reg_exp="true" />

Or Should I use only those attributes which are registered in the native DOM like html id, classname,tagname, in the toolkit config xml's Condition element.

One of our add-in developer used an external functional call like the one below in the tool kit config xml to demonstrate the use of those new attributes given by the app developer.

             <Identification function="isExtjsButton">

But I came to know from the QTP help file that using external function calls like this in the toolkit config xml would affect the performance of the add-in and should be avoided. I asked the developer to check if those custom attributes be used directly in the condition element and avoid making an external function call. But we could not crack it. An help on how to do this would be appreciated

Regards

Srinivas

Upvotes: 3

Views: 848

Answers (2)

Vishal Aggarwal
Vishal Aggarwal

Reputation: 4239

Did you try using Xpath -axis? I mean using the stable Ids of the parent element and fetching the dynamic id at runtime of the desired object.In our case we found that every object at some level was wrapped in a table having stable id. You may develop the similar logic based on your objects hiararchy.

Logic like Below:

	Set objTableName=Description.Create() ' Creating description object for Web Table
	' Setting the Web Table object properties to navigate to parent and then to child
	objTableName("micclass").value = "WebTable" 
	objTableName("class").Value="some-stable- part-in-the-table -class.*"
	objTableName("name").Value=strParentTableName
	' Check for the object existency and fetch the exact html ID for Dropdown List at run time
	If Browser("B").Page("P").Webtable(objTableName).Exist(gMaxTimeout)=True Then
		strTableText = Browser("B").Page("P").Webtable(objTableName).GetROProperty("outerhtml") 
	   	Set objRegEx = New RegExp   ' Create a regular expression.	   	
	   	objRegEx.Pattern = "ext-gen[0-9]+"
	   	objRegEx.IgnoreCase = True   ' Set case insensitivity.
	   	objRegEx.Global = True   ' Set global applicability.
	   	Set objMatches = objRegEx.Execute(strTableText)   ' Execute search.
	   	For Each objMatch in objMatches      ' Iterate Matches collection.
	   		strComboHtmlID = objMatch.Value
	   	Next	   
	   	Browser("B").Page("P").WebElement("html id:=" & strComboHtmlID ).Click ' Click on the Dropdown List
	   	'Check for Web element existency and performing click operation
	   	If Browser("B").Page("P").WebElement("innerhtml:=" & strValuetoBeSelected,"index:=1","class:=x-nowrap-combo-item").Exist(gMinTimeout) Then 
	   		Browser("B").Page("P").WebElement("innerhtml:=" & strValuetoBeSelected,"index:=1","class:=x-nowrap-combo-item").Click

Upvotes: 0

Srinivas Aditya
Srinivas Aditya

Reputation: 91

at last contacted HP QTP support. They informed me that the custom attributes given by the app developer should be part of native DOM properties for them to be used directly in the Condition element of toolkit config xml. As the custom attributes are not part of native DOM, the only way out is to use external function call. So the external function call is inevitable.

Upvotes: 2

Related Questions