Descriptive Programming in UFT with Examples

Whenever UFT records any action on any object of an application, it adds some description on how to recognize that object to a repository of an object called Object Repository.UFT can’t take any action on an object until its object description is in the Object Repository. However descriptive programming in UFT provides a way to perform an action on an object which is not present in the Object Repository.

When and why to use Descriptive Programming in UFT?

Below are some of the situations when Descriptive Programming can be considered useful:

  • The objects in the application are dynamic in nature and need special handling to identify the object. The best example would be clicking a link that changes its text property according to the user of the application. Example “Logout”<>
  • When the object repository is getting huge due to the number of objects being added. If the size of the Object Repository increases too much, it might decrease the performance of UFT while recognizing the object.
  • When you don’t want to use the object repository at all.
  • Modification to a test case is needed but the Object Repository for the same is in Read-only or in a shared mode i.e. changes may affect other scripts as well.
  • When you want to take action on a similar type of object i.e. suppose we have 20 text boxes on a page and the only change in their property is either their name or ID or both. Now adding all 20 textbox objects in the Object Repository would not be a good programming approach.

How to Use Descriptive Programming in UFT?

There are two ways to use descriptive programming
  • By creating properties collection object for the description
  • By giving the description in form of the string arguments

DP Method 1: By creating properties collection object for the description

To use this method you first need to create an empty description

Dim ObjDesc ‘ Not necessary to declare
Set ObjDesc = Description.Create

 Now we have a blank description “ObjDesc”.Each description has 3 properties “Name”, “Value” and “Regular Expression”

When you use a property name for the first time the property is added to the collection and when you use it again the property is modified. By default, each property is defined as a regular expression. Suppose if we have the following description.

 ObjDesc(“html tag”).value = “INPUT”
 ObjDesc(“name”).value = “txt.*”

This would mean an object with an HTML tag as INPUT and name starting with txt. Now actually that “.*”
was considered as a regular expression. So, if you want the property “name” not to be recognized as a regular expression then you need to set the “regularexpression” property as  FALSE.

The above example shows how we create a description. Now we use the above descriptive object in the following way.

When we say WebEdit(ObjDesc) we define one more property for our description that was not define earlier that’s it’s a text box because of UFTs WebEdit box map against the textbox class in a web page.
If we know that we have more than one object with the same description on the page, in that case, we must define the “Index” property for that description.
Consider the following HTML code.

Descriptive Programming html code 1

Now the HTML code has two objects with the same description. In order to distinguish between these two objects, we will use the “index” property. Here is the description for both the object.

For the first textbox:

For the second textbox:

Consider the following HTML code

Descriptive Programming UFT

We can use the same description for both objects and still distinguish between both of them.

When you want to refer to the text box then you can use the object description inside a WebEdit box and to refer to a radio button you will have to use the description object with the WebRadioGroup object.

But if you use a webelement object for the description then we must define the ‘index” property because for a webelement the current description would return two objects

Hierarchy of Test Description

When using a programmatic description from a specific point within a test object hierarchy, you must continue to use a programmatic description from that point onwards within the same statement. If you specify a test object by its object repository name after other objects in the hierarchy has been described using programmatic descriptions, UFT cannot identify the object.

For example, you can use the below one as it uses programmatic descriptions throughout the entire test object hierarchy.

Browser(Desc1).Page(Desc2).Link(Desc3).Click

You can also use Browser(“Google“).Page(Desc2).Link(Desc3). Click since it uses a programmatic description from a certain point in the object hierarchy (starting from the page object. The parent Browser test object refers to the test object in the Object Repository)

However, you can not use Browser(Desc1).Page(Desc2).Link(“Gmail”).Click, since it uses programmatic description for the Browser and Page objects but then attempt to use an object repository name for the Link test object. (UFT tries to locate the Link object by its name, but can not locate it in the object repository because parent objects were specified using programmatic descriptions).

Getting Child Objects Using ChildObjects Method

We can use a description object to get all the objects on the page that matches that specific description. Suppose we have to check all the checkboxes present on a web page. So we will first create an object description for all checkboxes and then get all the checkboxes from the page.

Set ObjDesc= Description.Create
ObjDesc(“html tag”).value=”INPUT”
ObjDesc(“type”).value=“checkbox”
Set allCheckBox = Browser(“Browser”).Page(“Page”).ChildObjects(ObjDesc)
Foreach chkbox in allCheckBox

    chkbox.Set “On”
Next

DP Method 2: By giving the description in form of the string arguments

You can describe an object directly in a statement by specifying property:=value pairs describing the object instead of specifying an object’s name. The general syntax is as follows

TestObject(“Propertyname1:=PropertyValue1,”…”,PropertynameN:=PropertyValueN”)

TestObject is the test object’s class. It could be WebEdit, CheckBox, etc.

Propertyname:=PropertyValue – the test object property and its value.  Each property:=value pair should be separated by commas and double quotation marks. Note that you can enter a variable name as the property value if you want to find an object based on property values you retrieve during a run session.

Consider the HTML code given below

Descriptive Programming UFT 3

Now to refer to the text box, the code would be as given below.

And to refer to the radio button the statement would be as given below.

Recommended Posts

Leave a Reply