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 <username>”.
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
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.





August 14th, 2008 at 3:29 am
Thank you mam, this blog has been a great help in revising the concept on a short notice.
August 21st, 2008 at 8:56 am
Can you please tell me some practicle scenarios where we should used descriptive programming and where normal scripting in QTP not work. This is a very common question asked in interviews. I wud be thankful
August 23rd, 2008 at 4:42 am
Hi Kanika,
Please find the answer to your query …..
Take case of a scenario where objects are dynamically created. For e.g. at the time of online hotel reservations , suppose you are booking hotel for 2 people , so in personal information form app will display the text boxes according to the no of passengers you have mentioned.
Suppose you want to test ,whether the application is able to book room for 1 passenger and for more than 1 passenger. Every time we run the script for different no of passengers, different number of text boxes will be generated in order to save the personal information of the passengers. Either we add all the possible text boxes in the OR based on index. Which might not be a very good idea reason being, if the number of passengers is large and similar fields occur in many pages it would lead to loads of redundant objects in the OR.
Better solution would be to use Descriptive programming. Based on number of passengers, we can use DP to modify the script dynamically based.
For instance see below a sample script, which based on number of passengers would write into text fields with passenger names. We use Index property of field to identify and write into the passenger fields.
Var_Num_Passenger = 5
For i = 0 to Var_Num_Passenger-1
Dialog(”Reservation”).WinText(”attached_text:=PassengerName”,”index:=”& (Var_Num_Passenger-1)).set “Name”
Next
–I hope this will make the concept of DP ore meaningful
September 5th, 2008 at 3:00 am
Hi………..Thanks a lot for your information about the DP. I learned a new thing. I have a doubt: How can we connect remote desktop through QTP and write the script for that application? QTP 9.2 is loaded in my system but it isn’t loaded in the remote system.
Please give me a solution…….it’s very urgent
September 5th, 2008 at 3:02 am
please send the answer to my mail id: jyoti.krushna@gmail.com
September 8th, 2008 at 5:00 am
Hi Jyoti,
please note that it is not possible to do recording using QTP on application installed on remote desktop.If u want 2 do so u have to install QTP on the remote machine also where your application is also installed in order to access it.
You can connect to remote desktop by using
start->programs->Accessories->Communications->Remote Desktop Connection
and then give IP address of the machine that u want to connect.Give the username and password and domain in order to log in into the remote desktop and then open QTP on remote machine and access your application.
Pls revert back if u still have doubts–
thanks
parul wahi
April 14th, 2009 at 5:01 am
Hi Parul,
I need to automate an application which is on remote machine and QTP is on my machine.I am able to record and even the run the application which is on the remote machine,but there is one problem that QTP is identifying the object on the basis of Co-ordinates and not the properties.
Can u tell me any procedure how to record the application on the remote machine with the properties
April 15th, 2009 at 11:38 pm
Updendra,
In case the QTP is on your machine and AUT is on a remote machine, QTP would not be able to identify the unique objects within the AUT. Remote desktop screen would be treated as window and any operations you perform within it would be in terms of screen coordinates within that window.
And mind you there is no assurance that it will replay correctly every time and hence it is not advisable to do the same
April 20th, 2009 at 12:24 am
how to test popup with verification code.
April 20th, 2009 at 3:34 am
hi vir,
can u please explain your query little bit more !!!!!!!!!!
April 21st, 2009 at 5:51 am
Hi Parul,
Thanks for ur reply i have one more query,if u know help me out.
1) Can u tell me wat is Silent installation of QTP and how to do it.
2)I send a mail regarding using QTP to AUT inRDP and i got this responce can you please tell me the meaning of this statement.
“Are you guys using VMs to deploy your machines? If so, you could probably getting away of testing against the VM image and then cookie cut the rest of the environments”
June 17th, 2009 at 2:03 am
A silent installation (or quiet installation) is an installation that is performed in the background without the need to navigate through setup screens or for user interaction. You can
also install QuickTest Professional, QuickTest Add-ins, and the Quality Center Add-in on remote computers.
The following prerequisite software is required to be installed on your computer before you install QuickTest Professional
• .Net Framework 2.0
• Microsoft Visual C++ Run-time Components
• Microsoft Data Access Components 2.8 SP1
• Microsoft Windows Script 5.6 for Windows 2000
• Microsoft MSI 3.1
• For the Web Services Add-in: MSE 3.0 Runtime
• In addition, for the .NET Add-in:
• Microsoft WSE 3.0 Runtime
• Microsoft SOAP Toolkit 3.0
To perform a silent installation of QuickTest and QuickTest Add-ins:
1 Install the prerequisite software for QuickTest Professional.
2 Run the Microsoft MSI installation:
• If you are running a new installation (any previous versions of QuickTest have already been uninstalled), use a standard msiexec.exe command from the command line.
For example, to install QuickTest silently in the default folder, with default add-ins, use:
msiexec /i /qn “\HP_QuickTest_Professional.msi”
• If you are upgrading from version 9.5, run a command similar to the following from the command line:
msiexec /i /qn “\HP_QuickTest_Professional.msi” ALLOW_UPGRADE=1 TARGETDIR=
where:
is the path of the HP_QuickTest_Professional.msi file from your DVD drive. The QuickTest Professional .msi files are located on the installation DVD in the QuickTest\MSI folder. There is a different msi file for each available language.
is the full path string (in quotes) of the folder in which the previous version of QuickTest Professional is currently installed.
Running a Silent Installation Remotely
To run a silent installation remotely:
1 All the prerequisite software for QuickTest Professional must be installed on the remote computers before you run a silent installation.
2 Run the Microsoft MSI quiet installation from the command line.
• The QuickTest Professional .msi files are located on the installation DVD in the QuickTest\MSI folder.
msiexec /i /qn “\HP_QuickTest_Professional.msi”
Foir more information study qtp INSTALLATION GUIDE.
For your second questions kindly elaborate the quiery.
October 13th, 2009 at 7:11 am
I have a query in QTP, could you please give your idea on this.
In our current project for regression execution we are supposed to place two different files in different folders in Unix server, from local drive.
Can this task be done through QTP
October 26th, 2009 at 10:55 pm
Hi,
My name is satish kumar I am new to the testing I am learing the QTP.I want to know to the how to write write Descrpive programin in QTP.
October 26th, 2009 at 10:58 pm
Hi cany you give some good real time scenario’s and send the any tutorial to my mail Id
Mi mail Id is : satishkumardega@gmail.com