What is descriptive programming in QTP ? How to Do descriptive programming? Those are some common question QTP(Hp QuickTest Pro) users. Descriptive programming is a way for QTP to bypass Object Repository(OR). In this tutorial i will show how to do Descriptive programming. If we want to perform an operation on an object that is not stored in the object repository then we use Descriptive programming.
Here are some advantages of using descriptive programming :
1. Descriptive Programming based Test Scripts run on any Machine easily.
2.Test scripts runs faster than OR based scripts.
3.Easy Maintenance because it doesn’t depend on Object Repository.
There are different ways to create descriptive programming in QTP. Follow rest of the tutorial to find out more about Descriptive Programming:
First way to do Descriptive Programming in QTP:
Example Using Google Search
Step 1: At first we are going to run Internet Explorer. In QTP we use systemutil.Run command to run any program. To do so the syntax will be:
systemutil.Run "The program we want to run", "the website Address"
Example for opening www.google.com
systemutil.Run "iexplore.exe", "www.google.com"
Step 2: Now we are going to declare variable for this example we are using :
googleSearchText = For the the google search text box.
googleSearchBtn = For Google search button description.
anyPage = For Describing a browser and page.
For Example:
Dim googleSearchText,googleSearchBtn,anyPage
Step 3: Then We are going to initialize the anyPage variable. We are going to set it to run on any page. Look at the code below:
Set anyPage = Browser("micclass:=Browser").Page("micclass:=Page")
The purpose of initializing this into variable is to shortening the code.
Step 4: In this step we are going create and describe the objects. Using QTP Object Spy you can get object Properties. It shows the types and properties of an object. Here is what object spy looks like.
It’s possible to get these properties :Syntax for creating and describing object in QTP :
Set Variable_Name = Description.Create Variable_Name("property").value = "properties from APP" Variable_Name("property").value = "properties from APP"
Here is an example for describing googleSearchText,googleSearchBtn :
Set googleSearchText = Description.Create googleSearchText("micclass").value = "WebEdit" googleSearchText("type").value = "text" googleSearchText("name").value = "q" Set googleSearchBtn = Description.Create googleSearchBtn("micclass").value = "WebButton" googleSearchBtn("name").value = "Google Search"
Step 5: Now we are going to put all the created objects together to use it. So far we created a Any page object, Google search text box and Google Search button. To use all the object together the syntax is:
anyPage.Type of object(Object Name).command "what we want to search"
Example
anyPage.WebEdit(googleSearchText).Set "Bytetips QTP Tutorial"
This is the Final script we created using descriptive programing. This script will start Internet Explorer and navigate to Google and search for the text provided in the text field. You can copy-paste this script inside qtp to see how this thing works.
systemutil.Run "iexplore.exe", "www.google.com" Dim googleSearchText,googleSearchBtn,anyPage Set anyPage = Browser("micclass:=Browser").Page("micclass:=Page") Set googleSearchText = Description.Create googleSearchText("micclass").value = "WebEdit" googleSearchText("type").value = "text" googleSearchText("name").value = "q" Set googleSearchBtn = Description.Create googleSearchBtn("micclass").value = "WebButton" googleSearchBtn("name").value = "Google Search" anyPage.WebEdit(googleSearchText).Set "Bytetips QTP Tutorial" anyPage.WebButton(googleSearchBtn).Click
Second way to do Descriptive Programming in QTP: The first way is a bit long process. We can do inline descriptive programing to shorten the script.
Step 1: At first we are going to run Internet Explorer. In QTP we use systemutil.Run command to run any program. To do so the syntax will be:
systemutil.Run "The program we want to run", "the website Address"
Example for opening www.google.com
systemutil.Run "iexplore.exe", "www.google.com"
Step 2: Now we are going to declare variable for this example we are using :
anyPage = For Describing a browser and page.
For Example:
Dim anyPage
Step 3: Then We are going to initialize the anyPage variable. We are going to set it to run on any page. Look at the code below:
Set anyPage = Browser("micclass:=Browser").Page("micclass:=Page")
The purpose of initializing this into variable is to shortening the code.
Step 4: In this step we are going create and describe the objects. This time Syntax for creating and describing object would be :
Page object.Type of object(Object Name).command "what we want to search"
For Example :
anyPage.WebEdit("micclass:=WebEdit","name:=q","type:=text").Set "Bytetips QTP Tutorial"
Step 5: Now we can put all our code together Look at the code below:
systemutil.Run "iexplore.exe", "www.google.com" Dim anyPage Set anyPage = Browser("micclass:=Browser").Page("micclass:=Page") anyPage.WebEdit("micclass:=WebEdit","name:=q","type:=text").Set "Bytetips QTP Tutorial" anyPage.WebButton("micclass:=WebButton","name:=Google Search").Click
Another way to make the script short
systemutil.Run "iexplore.exe", "www.google.com" Dim anyPage Set anyPage = Browser("micclass:=Browser").Page("micclass:=Page") With anyPage .WebEdit("micclass:=WebEdit","name:=q","type:=text").Set "Bytetips QTP Tutorial" .WebButton("micclass:=WebButton","name:=Google Search").Click End With
Second way to do Descriptive Programming in QTP: Here is another way to create object in QTP. This time we are going to use Const and initialize the variable with object property.
systemutil.Run "iexplore.exe", "www.google.com" Const dpBrowser = "micclass:=Browser" Const dpPage = "micclass:=Page" Const googleSearchText= "name:=q" Const googleSearchBtn="name:=Google Search" Browser(dpBrowser).Page(dpPage).webedit(googleSearchText).Set "Bytetips QTP Tutorial" Browser(dpBrowser).Page(dpPage).webButton(googleSearchBtn).Click