Descriptive programming in UFT

Descriptive programming in UFT

What is Descriptive Programming?

Descriptive programming is a way writing and implementing QTP scripts by avoiding the object repository. Usually Non – Descriptive programming access this object repository, where the required object’s properties and values are stored, and execute the scripts.

While in Descriptive programming, the object properties and values are directly written in the code so no need to access the object repository while script execution time.

For example.

If QTP script needs to close a browser the following descriptive program can be used and it can close any single open browse no matter what is the content or name of the browser.

Browser(“micClass:=Browser”).close

What are the common ways that the Descriptive Programming scripts can be written?

1. Static Descriptive Programming

Here the object properties and values are directly written in the code assuming that we know the expected properties and values.

For example.

If scripts wanted to input user name and password and click ok button to login to an application.

Browser(“micClass:=Browser”).Page(“micClass:=Page”).WebEdit(“type:=text”,”name:=username”).set “– USERNAME”

Browser(“micClass:=Browser”).Page(“micClass:=Page”).WebEdit(“type:=text”,”name:=password”).set “PASSWORD”

Browser(“micClass:=Browser”).Page(“micClass:=Page”).WebButton(“type:=Button”,”name:=Login”).set “LOGIN”

2. Dynamic Descriptive Programming

Here the object properties and values collections are created and used while scrip execution time

‘ this is to declare the object variable

Dim oDesc

‘to create an blank description

Set oDesc = Description.Create

Now assign values to the blank description in “oDesc”

oDesc(“type”).value= “text”

oDesc(“name”).value= “username”

now implement it in code as below

Browser(“micClass:=Browser”).Page(“micClass:=Page”).WebEdit(oDesc).Set “– USERNAME”

Note: Dynamic Descriptive Programming is really helpful when you want to handly an array of objects and child objects.