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 they keep on changing based on some input or other factors. For example, Text property of a Date label on an application would change every other day.
- The size of object repository is getting huge due to too many objects in a single object repository or maintenance of multiple objects repositories has become a time consuming activity. 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 script is needed, but the Object Repository associated with the test is currently in Read-Only mode as it is being shared with other team members and someone else has checked out it and you can’t immediately modify it.
- 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?
- By creating properties collection object for the description
- By giving the description in the form of the string arguments
DP Method 1: By creating properties collection object for the description
Dim ObjDesc ‘ Not necessary to declare
Set ObjDesc = Description.Create
1 |
ObjDesc("html tag").value="INPUT" |
ObjDesc(“html tag”).value = “INPUT”
ObjDesc(“name”).value = “txt.*”
1 2 3 |
ObjDesc("html tag").value = "INPUT" ObjDesc("name").value = "txt.*" ObjDesc("name").regularexpression = FALSE |
The above example shows how we create a description. Now we use the above descriptive object in the following way.
1 |
Browser("Browser").Page("Page").WebEdit(ObjDesc).Set "TESTVALUE" |
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:
1 2 3 |
ObjDesc("html tag").value="INPUT" ObjDesc("name").value="txt_Name" ObjDesc("Index").value=0 |
For the second textbox:
1 2 3 |
ObjDesc("html tag").value="INPUT" ObjDesc("name").value="txt_Name" ObjDesc("Index").value=1 |
Consider the following HTML code
We can use the same description for both objects and still distinguish between both of them.
1 2 |
ObjDesc("html tag").value="INPUT" ObjDesc("name").value="Name123 |
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.
1 2 |
Browser("Browser").Page("Page").WebEdit(ObjDesc).Set "TESTVALUE" Browser("Browser").Page("Page").WebRadioGroup(ObjDesc).Set "TESTVALUE" |
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
Now to refer to the text box, the code would be as given below.
1 2 |
Browser("Browser").Page("Page").WebEdit("Name:=Test123","html tag:=input").Set "TestValue" |
And to refer to the radio button the statement would be as given below.
1 |
Browser("Browser").Page("Page").WebRadioGroup("Name:=Test123","html tag:=input").Click |
Recommended Posts
- How to Use Insight Object in UFT
- Action Input And Output Parameters In UFT
- Read, Write and Update Excel File In UFT
- Web Table Methods in UFT With Example
- Settings.WebPackage Replaytype in UFT
- How to Use Virtual object in UFT to Identify Non-Standard Class Objects
- DataTable in UFT One | Example of Datatable Methods
- File System Object (FSO) in UFT
- VBScript Loops: Do Loop, For Loop, For Each, and While Loop