When you record an operation on an object QTP add the appropriate test object to the OR. QTP can not take action on an object until unless object descriptive is in OR.

For example, in the below statement ‘username’ is the name of an edit box. The edit box is located on the page with the name Mercury Tours, and the page was recorded in a browser with the name Mercury Tours.

Browser(“Mercury Tours”).Page(“Mercury Tours”).WebEdit(“username”)

Because each object in the OR has unique name, the object name is all you need to specify. during the run session, QTP finds the object in the OR based on its name and parent objects.

You can also achieve the same thing by using Descriptive programming with out referring OR.

When and why to use the Descriptive Programming?

Some of the situation when Descriptive programming can be consider useful:
1- The Objects in the application are dynamic in nature and need special handling to identify the object. for example, clicking on a link which changes according to the user of the application “Logout{username} ”
2- When OR is getting huge due to number of objects been added. If the size of the OR increase too much then it decrease the Performance of the QTP.
3- When you don’t want to use OR at all. Consider the following example
-Suppose we have a application that has not been developed yet.
-Suppose an application has three navigation buttons on every page “Cancel”, “Back” and “Next”, recording action on these buttons would add 3 objects per page in the OR.
4- When you want to take action on similar type of object.

There are two types of Descriptive Programming.
Static:- List the set of properties and values that describe the object directly in the VBScript Statement.
For example,
MyVar = “Some text string”
Browser(“Title:= Mercury Tours”).Page(“Title:= Mercury Tours”).WebEdit(“Name:=” &MyVar)

Note:- When using Descriptive Programming from a specific point with in a test object hierarchy, you must continue to use Descriptive Programming. If you specify a test object by its OR name after other object in the hierarchy have been specified using Descriptive Programming, QTP can not identify the object.

For example,
Browser(“Title:= Mercury Tours”).Page(“Title:= Mercury Tours”).WebEdit(“usename”)
‘username is object in OR

Dynamic:- Add a collection of properties and values to Description object, and then enter the Description object name in the statement.

For example,
Dim objDesc
Set objDesc = Description.Create
‘Now you have Description object, each description object has 3 properties “name”, “value” and “Regular Expression”

objDesc(“html tag”).value = INPUT
objDesc(“name”).value =”txt.*”
objDesc(“name”).regularexpression=”txt.*”
‘ Means an object with html tag as INPUT and name starting with txt. Now actually that “.*” was consider as regular expression So, if you want the property “name” not to be recognized as a regular expression then you need to set the “regulerexpression” property as FALSE.

Note:- When using Descriptive Programming from a specific point with in a test object hierarchy, you must continue to use Descriptive Programming. If you specify a test object by its OR name after other object in the hierarchy have been specified using Descriptive Programming, QTP can not identify the object.

Getting Child Objects:
We can use the description object to get all the objects on that page that matches that specific description. Suppose we have to check all the CheckBoxes present on the web page.

Dim objDesc
Set objDesc = Description.Create
objDesc(“html tag”).value = “INPUT”
objDesc(“type”).value = “checkbox”

Dim allChkBoxes, sglChkBox

Set allChkBoxes = Browser(“Browser”).Page(“Page”).ChildObjects(objDesc)
For each sglChkBox in allChkBoxes
sglChkBox.Set “ON”
Next

Reference: QTP user’s Guide, Version 9.5

Related posts:

  1. Test and Run time Objects
  2. How Objects are added to the OR?
  3. QTP Interview Questions
  4. QTP XML Objects
  5. Boundary Value Analysis and Equivalence partitioning (EP)

One Response to “Descriptive Programming in QTP”

  1. Why learn PHP? There are many of software engineers on the Internet. care about shoveling out $125 an hour to a complete stranger.

Leave a Reply