Descriptive programming is creating of description of
objects so that they can be identified once executed from QTP. It is approach for object identification together with object repository.
Description object creates a collection
of object based on object matching the defined properties.
we have defined an description object odesc.
We can use ochkbox.count to get objects
matching the description
Why Descriptive Programming:
Descriptive
programming is useful due to following reasons:
- It reduces the effort of maintaining and associating object repository with the test.
- Maintenance is simpler.
- In scenarios, when application is not developed but we know the properties of objects that will be added in the application. In such scenarios , we cannot maintain object repository since application is not ready and Objects cannot be learned from the application. So Using Descriptive programming, we can prepare the scripts which can be executed once application is up and running.
- It is useful when performing similar actions on multiple objects with similar properties
- It is useful when object can be uniquely identified using fewer set of properties existing across multiple set of objects.
OR Vs Descriptive programming
When QTP learns an object during recording session or
through object spy, object is identified and saved in object repository. QTP
saves properties like innertext, name for the object in the object repository
to uniquely identify an object. Similar to this, Descriptive programming
creates a unique description of the object which is identified.
With using Object Repository, we can use features like relative identifier, and other QTP specific features. Also time to create
script based on descriptive programming is more compared to object repository. So for projects and for limited use of automation pack and applications with mostly static pages, Object repository can be
better approach.
Types of Descriptive programming
Descriptive Programming can be implemented in following
ways.
- Creating description string
- Using Description object.
Let us discuss the ways in some
details:
- Creating description string:
Browser("title:=Google").Page("title:=Google").WebEdit("name:=q").Set
“DP”
Above we created a description string similar
to tree structure we see in expert view.
Below are few points to remember in creating description strings.
1. The parent object in the string can be used from
Object repository, in case child object is defined in string.
2. Child objects cannot be used from OR if string description is described for parent
in the tree.
Browser("Google").Page("Google").WebEdit("name:=q").Set
“DP” is possible but
Browser("title:=Google").Page("title:=Google").WebEdit("q").Set
“DP” will not identify the object
In case multiple objects are to defined , they needs to be separated by , .
In case multiple objects are to defined , they needs to be separated by , .
Browser("title:=Google").Page("title:=Google").WebEdit("name:=q”,html
tag = In").Set “DP”
To identify the properties of the
object to be used in descriptive programming, Go to Object Spy and click on
object.
- Go to Identification button and properties tab
- Select properties and property values and create string such that the identification is unique.
In case of multiple objects with
same properties, we can use index property to identify object based on indexing.
- Using Description.Create:
Description object creates a collection
of object based on object matching the defined properties.Steps in description Object
1. Define description object:
set odesc = description.createwe have defined an description object odesc.
2. Add property to the object defined in step
above.
odesc(“name”).value =”q”
odesc(“html tag”).value
=”Input”
we have defined the object with properties.
3. Replace string with description object.
Browser("title:=Google").Page("title:=Google").WebEdit(odesc).Set
“DP”
we have replaced string with description object.
This description object can also be used to find child
objects in the tree structure. For e.g : we can find all the links in the pages, check box, perform action on all the objects in the collection.
Below code explains the same:
odesc = Description.create
odesc(‘”html tag”).value =”Input”
odesc(“type”).value = “checkbox”
Set ochkbox =
Browser("title:=Google").Page("title:=Google").childobjects(odesc)
For each obj in ochkbox
obj.set “ON”
Next