Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts

Showing posts with label descriptive programming. Show all posts
Showing posts with label descriptive programming. Show all posts

XPath Object Identification in UFT descriptive programming

UFT also supports XPATH and css together with descriptive programming, object repository and DOM for object Identification.

Xpath stands for Xml Path. Below are some XPath examples to be used with UFT. Xpath and css are most widely used object identification way in selenium also.


Xpath examples:

Id: 

Browser(...).Page(...).weblink("xpath:=//a[@id='linkuft']").click

Attribute Value:

Browser(...).Page(...).weblink("xpath:=//a[@Atttribute='goodclass']").click

text:

Browser(...).Page(...).weblink("xpath:=//a[text()='UFT']").click 

partial attribute value

Browser(...).Page(...).weblink("xpath:=//a[starts-with(@attribute,'goodclass']").click

Browser(...).Page(...).weblink("xpath:=//a[contains(@attribute,'goodclass']").click

Browser(...).Page(...).weblink("xpath:=//a[ends-with(@attribute,'goodclass']").click


To know details on what is CSS and XPath and how to capture CSS or xpath of an element. refer to

XPath and CSS for selenium/UFT

We can use tools like firebug/firepath or IE developer tool to identify the xpath/css of an element.

xpath is really useful when element is not identified diretly based on Object repository properties and used to
identify an element based on relative element existence based on other elements in the tree.

Descriptive Programming in UFT : 10 Key points

1. Descriptive programming is describing the object properties in the code itself instead of defining an object in the object repository.

2. Descriptive programming has two flavors: 
 a.) Static DP
 b.) Dynamic DP

3. Static DP defines the object property in inline description in the Page tree structure as defined below:
''example 3.1) - In case all the object in the tree are defined as static DP
Browser("title:=Bing").Page("title:=Bing").WebEdit("name:=qb").Set "test automation"

''example 3.2) Multiple properties are used to uniquely identify an element,
 the properties are seperated by ,
Browser("title:=ng").Page("title:=ng").WebEdit("name:=qb", "type:=input").Set "test"


4. The structure of element in the page follows the tree structure as Browser --> Page --> WebElement.
We cannot define browser and page as descriptive programming, in case  last element in the tree(WebEdit, WebElement is defined from Object repository.

5. Dynamic description example is shown below:
Set objdescBR = description.Create
objdesc("title").value ="Google"
Set objdescPg = description.Create
objdescPg("title").value ="Google"
Set objdesc = description.Create
objdesc("micclass").value ="Link"
Set objLinks = Browser(objdescBR).Page(objdescPg).childobjects(objDesc)
Msgbox objLinks.count

6. Dynamic description is useful to perform similar action on group of elements. e.g: get the text of all the links in the page.

7. Set objLinks = Browser(objdescBR).Page(objdescPg).childobjects(objDesc) returns list of elements. This can be a list of links in the page or multiple checkbox
in the page.

8. We can access each element of group of element using objLinks(index) as shown below:
For i=0 to objLinks.count -1 to Step 1
 objLinks(i).GetRoProperty("name")
Next

9. Descriptive programming is very useful in case of:

9.1 - Common element definition used across a set of pages in the application. e.g: Canel, OK, New button
9.2 - In case of DP programming used in function libraries, the objects are defined in Function library and can be used in multiple tests.
9.3 - Performing same action with multiple elements with similar properties.
9.4 - Maintaining OR can be complex and OR size may grow considerably in the application. 
9.5 - Application is not ready. 
9.6 - Keyword driven framework.
9.7 - A good approach is to use a mix of Object Repository and Object repository and xpath definition.

10. Regular expression can be used together with Descriptive programming, which can again be part 
of another article 10 things to know, regular expression with descriptive programming.