QTP scripts can execute only if the objects are present in the Object Repository. The descriptions of the Objects are created using Descriptive programming −
When the 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.
There are two ways to scripting using Descriptive Programming technique. They are −
Script is developed using Description Objects that depend upon the properties used and their corresponding values. Then, these descriptions are used to build the script.
'Creating a description object Set btncalc = Description.Create() '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
The description of the objects is 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
QTP provides the ChildObjects method, which enables us to create a collection of objects. The parent objects precedes ChildObjects.
Dim oDesc Set oDesc = Description.Create oDesc("micclass").value = "Link" 'Find all the Links Set obj = Browser("Math Calc").Page("Math Calc").ChildObjects(oDesc) Dim i 'obj.Count value has the number of links in the page For i = 0 to obj.Count - 1 'get the name of all the links in the page x = obj(i).GetROProperty("innerhtml") print x Next
Descriptive programming is used to write the script based on ordinal identifiers, which will enable QTP to act on those objects when two or more objects have the same properties.
' Using Location Dim Obj Set Obj = Browser("title:=.*google.*").Page("micclass:=Page") Obj.WebEdit("name:=Test","location:=0").Set "ABC" Obj.WebEdit("name:=Test","location:=1").Set "123" ' Index Obj.WebEdit("name:=Test","index:=0").Set "1123" Obj.WebEdit("name:=Test","index:=1").Set "2222" ' Creation Time Browser("creationtime:=0").Sync Browser("creationtime:=1").Sync Browser("creationtime:=2").Sync