Tuesday, May 26, 2009

Descriptive Programming in QTP

Descriptive Programming in QTP

By Parul Wahi

What is Descriptive Programming?

QTP can perform some action on objects at run time only when it is able to uniquely identify the object. In order to identify the object at run time (play back), QTP learns some physical properties of the object at the time of recording and stores them in object Repository (OR). When QTP runs the script, it compares these properties and values to the actual objects appearing in the application, and performs the action on the object if it finds it.

Thus, it is not possible for QTP to perform action on objects during run time if the objects are not there in OR. But descriptive programming provides a way to perform action on objects which are not in Object repository. We can instruct QTP to perform methods on the objects that are not there in object repository with the help of programmatic description or descriptive programming.

When and Why to use Descriptive programming?

When using Descriptive Programming (DP), we’re bypassing the native object repository (OR) mechanism which may have many advantages. Let’s examine the situations in which the OR’s advantages are outweighed by the DP.

Suppose we are testing the site that displays the list of users whose details matches with the search criteria that is entered in search text field. With the names, the application also displays checkboxes against each name. Now, we want to test the scenario where application sends mail to all the users whose names are displayed in the list. But we are not sure how many check boxes will be displayed on the page as the search criteria can differ . In this situation, you can use a programmatic description to instruct QuickTest to perform a Set “ON” method for all objects that fit the description: HTML TAG = input, TYPE = check box

The other usage of DP can be as follows:

1) Programmatic descriptions can be used to perform the same operation on several objects with certain identical properties, or to perform an operation on an object whose properties match a description that is determined dynamically during the run session.

2) One place where DP can be of significant importance is when you are creating functions in an external file. You can use these function in various actions directly, eliminating the need of adding object(s) in object repository for each action [If you are using local object repository]
3) The objects in the application are dynamic in nature and need special handling to identify the object. The best example would be of clicking a link which changes according to the user of the application, Ex. “Logout ”.

4) When object repository is getting huge due to the no. of objects being added. If the size of Object repository increases too much then it decreases the performance of QTP while recognizing a object.

5) When you don’t want to use object repository at all. Consider the following scenario which would help understand why not Object repository

Scenario 1: Suppose we have a web application that has not been developed yet.Now QTP for recording the script and adding the objects to repository needs the application to be up, that would mean waiting for the application to be deployed before we can start of with making QTP scripts. But if we know the descriptions of the objects that will be created then we can still start off with the script writing for testing

Scenario 2: Suppose an application has 3 navigation buttons on each and every page. Let the buttons be “Cancel”, “Back” and “Next”. Now recording action on these buttons would add 3 objects per page in the repository. For a 10 page flow this would mean 30 objects which could have been represented just by using 3 objects. So instead of adding these 30 objects to the repository we can just write 3 descriptions for the object and use it on any page.

6) When you want to take action on similar type of object i.e. suppose we have 20 textboxes on the page and there names are in the form txt_1, txt_2, txt_3 and so on. Now adding all 20 the Object repository would not be a good programming approach.

How to use Descriptive programming?

There are two ways in which descriptive programming can be used
• Static. You list the set of properties and values that describe the object directly in a VBScript statement.
• Dynamic. You add a collection of properties and values to a Description object, and then enter the Description object name in the statement.

Static method
In Static method , we can write down the physical description of the object in the script itself rather than using it’s logical name. The syntax for this is :
TestObject(”PropertyName1:=PropertyValue1?, “PropertyName2:= PropertyValue2?)
Where, TestObject is . The test object class. Eg WinButton , WebEdit , WinCheckBox etc
PropertyName:=PropertyValue. The test object property and the value identification string. Each property:=value pair should be separated by commas and quotation marks
Eg.1 DP code for login into the FLIGHT RESERVATION (sample Application of QTP) is :
Dialog(”text:=Login”).WinEdit(”nativeclass:=Edit”,”attachedtext:=Agent Name:”). Set “fgfdgfdgf”
Dialog(”text:=Login”).WinEdit(”nativeclass:=Edit”,”attachedtext:=Password:”).SetSecure “48a1881a08961df276749334f4511d5a7d35e922?
Dialog(”text:=Login”).WinButton(”text:=OK”,”nativeclass:=Button”).Click
Window(”title:=Flight Reservation”).Close
Dynamic Method

QTP provides another method which provides more efficiency, power and flexibility known as Dynamic method.

Under Dynamic method you can use the Description object to return a Properties collection object containing a set of Property objects. A Property object consists of a property name and value. You can then specify the returned Properties collection in place of an object name in a statement.

Eg2. The first example mentioned above for Flight Reservation application can be written as follows using Dynamic method:

Set desc=description.Create()
desc(”text”).value=”Login”
desc(”Class Name”).value=”Dialog”

Set agent=description.Create()
agent(”nativeclass”).value=”Edit”
agent(”attachedtext”).value=”Agent Name:”

Set password=description.Create()
password(”nativeclass”).value=”Edit”
password(”attachedtext”).value=”Password:”

Set button=description.Create()
button(”nativeclass”).value=”Button”
button(”text”).value=”OK”

Dialog(desc).WinEdit(agent). Set “fgfdgfdgf”
Dialog(desc).WinEdit(password).SetSecure “48a1881a08961df276749334f4511d5a7d35e922?
Dialog(desc).WinButton(button).Click
Window(”title:=Flight Reservation”).Close


http://www.qacampus.com
http://www.crestech.in
http://www.crestechsoftware.com.au

No comments:

Post a Comment