What is Descriptive Programming in UFT??

Spread the love
  • 2

What is Descriptive Programming in UFT?

Entering / Providing objects information directly into the test script is called Descriptive Programming.When QTP/UFT records any action on any object,it tries to identify the object with some of its properties. And stores them in object repository. Later point of time , during execution, it takes reference from it and tries to find out the object in the application and  perform set of operations.
So, if an object is not present in the object repository, QTP/UFT can not identify the object and perform operation on it.
With the fast development of application and agile way of developing software advocates more about descriptive programming. Imagine we need to design our test script without the GUI. Yes!! it is possible. Descriptive programming provides information to QTP/UFT bypassing object repository. The same object information is passed to QTP/UFT so that it can identify the object.

Lets think about a person whom we don’t know. When we meet for the first time, we create an image of that person. Like name, tentative age,gender,height,if the person wear specs or not etc.  For us to remember that persons these are enough. we will be able to identify the person in our next meet by using our stored properties of that person. These are mandatory properties. There are some other things we can notice. We may also notice the shirt color, trouser color, some more details. They are assistive properties. The help to identify the person uniquely. But they may change.

What is Descriptive Programming in UFT??

Likewise if we need to identify a textbox, the first thing we will be looking is the name or id. This will help me to identify the textbox.In this method of script creation, we no need to have Object Repositories.
But assume that we have a special application which is dynamic in nature. So with the stored object description QTP/UFT will not be able to identify the objects. Say after loggin we have a welcome message say Welcome <<UserName>>. Upon clicking on the username it will navigate to the actual page.
This will work fine if the same user logs in but fails when another user logs in as the stored object description does not match to the application object.So we need to find an another way of coding.
This is called Descriptive programming.

In real world if the person says I want to meet you and I will be seating some coffee hose, table number-2. I will be in red shirt. Then we will not try to find the person, directly go to that coffee house and go to table no-2. Now if I see a person with red shirt , we will get the person. Is not it??

So , in this method we provide information about the object to QTP and request it to perform search operation and carry out tasks.
In real project if the GUI is not available or the project size is getting bigger(OR will also bigger), we use descriptive programming.

a) Descriptive Programming based Test scripts are faster in execution than Repository based Test scripts.
b) Scripts are portable (we can run these scripts from any machine easily)
c) Maintenance is easy (less amount of resources)
d) We can start Test Execution process even though Application is not ready.

Descriptive programming is basically 2 types.
1. Static Programming
2. Dynamic Programming

Static Programming

In this style of script generation, we provide objects information directly into the script.

Invokeapplication "C:Program FilesHPQuickTest Professionalsamplesflightappflight4a.exe"
dialog("text:=Login").Winedit("attached text:=Agent Name:").Set "asdf"
dialog("text:=Login").Winedit("attached text:=Password:").Set "mercury"
1. Dialog, WinEdit and WinButton – Test Objects
2. text, attached text – Property names
3. Login, Agent Name:, Password:, OK – Property values or Logical Names of the Object
4. Activate, Set, Setsecure, Click – Methods
If we feel one property information is not sufficient for recognizing the object uniquely, then we can provide more properties information by separating with commas.
Note 3:
If we want to get objects information (Test objects, properties and values), we can use object spy feature. This feature is available in Tools Menu, in local repository and in repository manager.
If we want maintain ‘Objects information’ in centralized location then we can use Constants.
Creating Constants:
Const Login=”text:=Login”, Agent=”attached text:=Agent Name:”
Const Pwd =”attached text:=Password:”, Ok=”text:=OK”
Note: we can declare no of Constants in a line by separating with Camas (,), if we take other line then we have to use Const Statement again.
Creating a Library file
Place Constants in Notepad and save as .vbs file
Associate the Library file to QTP (File->Settings->Resources-> Click add (+) icon-> Browse path of the Library file->Click Apply and click Ok buttons
Otherwise, we can load the library file during run-time
ExecuteFile “Path of the Library file(.vbs)”
After that create the Test Script using Constants
Creating the Test Script using Constants:

Invokeapplication "C:Program FilesHPQuickTest Professionalsamplesflightappflight4a.exe"
Dialog(Login).Winedit(Agent).Set "asdf"
Dialog(Login).Winedit(Pwd").Set "mercury"

If we maintain Object Information in the centralized location, then we can handle modifications easily.

Dynamic Programming:

In this style of script generation, first we create description objects, provide properties information and use description objects in the test script.
Creating Properties Collection Objects

Set oLogin=description.Create
Set oAgent=description.Create
Set oPassword=description.Create
Set oOk=description.Create
//Entering Properties Information into Objects
oAgent(“attached text”).value=”Agent Name:”
oPassword(“attached text”).value=”Password:”
//Generating Tests using Properties collection Objects
Invokeapplication “C:Program FilesHPQuickTest Professionalsamplesflightappflight4a.exe”
Dialog(oLogin).Winedit(oAgent).Set “asdf”
Dialog(oLogin).Winedit(oPassword).Set “mercury”

Note1: Create Description objects and put into one library file, by associating that library file, we can generate tests.
Note2: Dynamic programming is some difficult in preparation than static programming but maintenance is very easy.
In this style of script creation also, we can maintain Objects information in the Centralized location by putting collection objects in a Library file.
Well,Here is the technique to write descriptive progranning…the main boost of my secrets…
Please follow the threads..

Descriptive Programming is an advanced concept of QTP coding. Testers can handle the application without using the OR by implementing the Descriptive programming.

  • They are reusable
  • Modification of the script becomes easy in compare to QTP Code
  • This is very useful when applications are not available
  • It is flexible for high performance of the application .
  • This is very speedy technique for execution
  • It can efectivey handle the object implementation problem of an application.
If the property values changes,it is necessary to upgrade the description.So maintenance is an issue for descriptive programming.


Few Common Example of Descriptive Programming:

How To Count The Numbers of Links On A Page and click on a link in QTP/UFT?

This is a very common scenario when automating a webpage. Say on a webpage I need to check if a particular link is available or not. Or there might be a scenario when you need to click on a particular link which is generating dynamically. If it is static then you can record and do. But which is dynamic in nature , for them we need to implement artificial intelligence.
Before we go ahead and code…Lets think about the logic.
Well , when we write a code for link we use to write like this……
< a href=”xyz.com”>Link Name1</a>
<a href=”deb.com”>Link Name2</a>
so through QTP if we can read the elements of a page and check if a “A” tag is there in the page element it will be surely a link.Isn’t it??
So, all the links looks like the same. And they follow the same pattern. This is small piece of code which will look like-

SystemUtil.Run http://www.yahoo.com/
Set aa=description.Create
// This type of coding is called descriptive programming.
set bb=Browser("name:=Fun.*").Page("title:=Fun.*").childobjects(aa)
msgbox cc

There is another way to find out the count of link

Set oDesc = Description.Create()
oDesc("micclass").Value = "Link"
//here we are filtering the object oDesc by its default class micclass. micclass of a link is "Link"
Set Links = Browser("Browser").Page("Google").ChildObjects(oDesc)
NumberOfLinks = Links.Count()
Msgbox NumberOfLinks

even, if, you need to click on a specific link you can modify the script little bit..say i have a link called yahoo.com and I need to click on the mail link.
Logic is again same …find out all the links
Now the extra is that we need to check if the link name is “Mail” . If so generate an click event.

SystemUtil.Run http://www.yahoo.com/
Set aa=description.Create
'either specifying here
set bb=Browser("name:=Fun.*").Page("title:=Fun.*").childobjects(aa)
for i=0 to cc-1
if bb(i).getROProperty("name")="Mail" then//link name
exit for
end if

How to check all checkboxes in a webpage/window in UFT or QTP?

Set a=Description.Create
a("html tag").value="input"
Set b=Browser("name:=").Page("title:=").childobjects(a)
msgbox c
For i=0 to c-1
b(i).set "on"

How to Close All Browser from QTP/UFT Code?


Most of the time I have seen that we need to close Internet Explorer while testing through QTP. Internet explorer means all the pop up , the main page. Say I am testing an application which need to navigate different URL. So what we generally do is to open a browser do what we want to do and close it for the next set of task may be in different URL.
A common testcase may be
1. Open IE and navigate to your HR link to create an employee.
2. After creation of the employee you need to close that and open another browser to register him to yahoo groups.
3. Now you need open some website called life insurance..fill up the data and employee number which is generated in Step-1.
4.Get the corresponding Policy number and again open HR link to update employee information.
For such cases to avoid the problem of multiple IEs we use to open a URL perform some task and close it after saving it.
Here is small code that will assist you to close an IE from QTP.

Sub CloseAllBrowsers()
End Sub

Now you can do further enhancement on this.
Say I have opened a meeting window and want to show my running window to our client or my seniors or there might be cases when I might open a test management tool like QC which runs on IE and want to run the test. So every time I will not be interested to open QC page.

This is a small modification on the code which will be helpful for such scenarios.

On Error Resume Next
Dim intWndCnt
Dim oDesc, oWnd
'Create Object description
Set oDesc = Description.Create '
Set oWnd = Desktop.ChildObjects(oDesc)
intWndCnt = oWnd.Count
For i = 0 to intWndCnt - 1
Set TmpObj = oWnd.item(i)
strTmpTitle = oWnd.item(i).GetROProperty("Text")
If instr(1,strTmpTitle, "Microsoft Internet Explorer",1) > 0 Then
If instr(1,strTmpTitle, "Mercury Quality Center",1) > 0 Then
'msgbox "Title :" & oWnd.item(i).GetROProperty("Text")
'msgbox "Close : & oWnd.item(i).GetROProperty("Text")
End if
End If
'Clean up
Set oDesc = nothing
Set oWnd = nothing

How to Calculate Number of Opened Browsers in QTP/UFT?


Function Browser_Count()
Set objBrowser =description.create()
Set sBrowsers=desktop.childobjects(objBrowser)
If ibCount<>0 Then
Else Browser_Count=1
End if
Set objBrowser=Nothing
Set sBrowsers=Nothing
End Function

How to Close Oracle Form in QTP/UFT??

This is one more situation which arises very common to an ERP test engineers. Most of the time we rely on QTP’s record feature. But this is scenario which occurs all most in every window of Oracle ERP Testing.
So instead of doing record playback in every time I tried to use some descriptive approach to make it a general case. So this can be treated as common function across the scenario.This is a code rather sub/procedure where we need to pass the form name as a parameter and this will close the form.

Sub ERP_CloseForm(sFrmName)
If OracleFormWindow("short title:="& sFrmName).Exist Then
OracleFormWindow("short title:="& sFrmName).CloseForm
End If
End Sub


How to Get Browser Title in QTP or UFT?

Function GetBrowserTitle()
set sbrowser=Description.create()
‘ we are creating a blank object named as sbrowser.
‘ we are assigning the sbrowser object as “Browser
set obj=Desktop.childObjects(sbrowser)
if(icount<>0) then
end if
Set sbrowser=Nothing
set obj=Nothing
End Function

How to Count Number of open Browsers in Desktop Using QTP/UFT?

For this the concepts we will be using are:
1. ChildObject
2. Descriptive programming

Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 2


  1. Hi Animesh,

    I have a question to you regarding an issue we faced today.
    Scenerio is:-
    1)We have an object as WebElement whose value is dynamically changing.For example,say i want to retrieve a policy number.When i added that object and retrieve with GETROPROPERTY,it is retrieving only one value which is added in the OR.For the next iteration it is throwing an error saying cannot find object.
    In this scenerio, we use regular expression,but using that it didnt helped.What are the other way to solve this issue?Please help me regarding this.



Please enter your comment!
Please enter your name here