QTP - DESCRIPTIVE PROGRAMMING
[Link] Copyright [Link]
Descriptive Programming:
QTP scripts can execute only if the objects are present in the Object Repository. If the descriptions
of the Objects are created using Descriptive programming when testers want to perform an
operation on an object that is not present in the object repository.
When objects in the application are very dynamic in nature.
When the Object Repository grows big, it results in poor Performance as the size of the Object
Repository increases.
When the framework is built such that it has been decided not to use Object Repository at all.
When testers want to perform an action on the application at run-time without having the
knowledge of object's unique properties.
Syntax
There are two ways to script using Descriptive Programming technique. They are
Description Objects
Description Strings
Description Objects
Script is developed using description Objects that depends upon the properties used and their
corresponding values. Then these descriptions are used to build the script.
'Creating a description object
Set btncalc = [Link]()
'Add descriptions and properties
btncalc("type").value = "Button"
btncalc("name").value = "calculate"
btncalc("html tag").value = "INPUT"
' Use the same to script it
Browser("Math Calc").Page("Num Calculator").WebButton(btncalc).Click
Description Strings
The description of the objects are developed using the properties and values as strings as shown
below.
Browser("Math Calc").Page("Num Calculator").WebButton("html
tag:=INPUT","type:=Button","name:=calculate").Click
Child Objects
QTP provides the ChildObjects method which enables us to create a collection of objects. The
parent objects preceeds ChildObjects.
Dim oDesc
Set oDesc = [Link]
oDesc("micclass").value = "Link"
'Find all the Links
Set obj = Browser("Math Calc").Page("Math Calc").ChildObjects(oDesc)
Dim i
'[Link] value has the number of links in the page
For i = 0 to [Link] - 1
'get the name of all the links in the page
x = obj(i).GetROProperty("innerhtml")
print x
Next
Ordinal Identifiers
Descriptive programming is used to script based on ordinal identifiers which will enable QTP to act
on those objects when two or more objects have same properties.
' Using Location
Dim Obj
Set Obj = Browser("title:=.*google.*").Page("micclass:=Page")
[Link]("name:=Test","location:=0").Set "ABC"
[Link]("name:=Test","location:=1").Set "123"
' Index
[Link]("name:=Test","index:=0").Set "1123"
[Link]("name:=Test","index:=1").Set "2222"
' Creation Time
Browser("creationtime:=0").Sync
Browser("creationtime:=1").Sync
Browser("creationtime:=2").Sync