Friday, May 27, 2011

How To Use Descriptive Programming In QTP Continued..


When And Where To Use Descriptive Programming:

In this article we will continue to learn "when and where to use Descriptive Programming in QTP?". What are the scenarios where one should use descriptive programming (Programmatic descriptions):
Just to list major scenarios below:


1. When object is not saved in Object Repository:

Descriptive Programming can be very useful if one want to perform an operation on an object that is not stored in the OR (Object Repository).

2. When many objects with same properties available in AUT (Application Under Test):

Descriptive Programming is also used in case where one has to perform the same operation on several objects with certain identical properties.

3. To handle dynamic objects:

It can also be used to perform an operation on an object whose properties match a description that one determines dynamically during the run session.
  
Here is an example to illustrate:
If there are multiple links in a particular section with different names, so it is not recommended to store all links in OR, better is to create properties collection and pass the name as parameter for “innertext”

 


Function clickLink(varLinkName)
 Set objDesc = description.Create()
 objDesc ("micclass").value = "Link"
 objDesc ("html tag").value="A"
 objDesc ("innertext").value = varLinkName
 Set objChild = Browser("Browser").Page("Page").ChildObjects(objDesc)
 objChild(0).Click
End Function

clickLink "Link1"
clickLink "Link2"


How To Use Descriptive Programming (Programmatic Description) In QTP Basics


Types Of Descriptive Programming:

Before starting to play with Descriptive Programming,one needs to understand the types of Descriptive Programming (programmatic descriptions).
Descriptive Programming can be of two types, Static and Dynamic:

1. Static Descriptive Programming:

    Example:
     
    
    
    Browser("Browser").Page("Page").WebEdit("Name:=Employee", "Index:=3").Set "John" 
    
    
    

    2. Dynamic Descriptive Programming: 

     One adds a collection of properties and values to a Description object, and then enters the Description object name in the statement.
    Example:
     
    
    
    Set objDesc = description.Create()
    objDesc ("micclass").value = "Link"
    objDesc ("html tag").value="A"
    objDesc ("innertext").value = "ClickHere"
    Set objChild =Browser("Browser").Page("Page").ChildObjects(objDesc)