Software Testing Learning Hub

Descriptive programming in QTP

Descriptive programming is used when we want to perform an operation on an object that is not stored in the object repository. This way QTP won’t search for the object properties in the Object Repository, but will take it from the Descriptive Programming statement.

Need of Descriptive programming-

To ease the operation of QTP for identifying browser,you want to close all currently opened browsers before you start executing your script.For closing this you need to identify the properties of opened browser and that is not the smart way of doing so in this case descriptive programming is useful.

Two ways of descriptive programming:
1. Static Programming
2. Dynamic Programming

1.Static Programming: We provide the detail  set of unique properties and values that describes the object directly in a VBScript statement.
    Example:

'Username="QEworks.com"

'Password="qtp”

‘Login to gmail account  using  Static descriptive Programming

'Launching a IE browser and gmail URL

systemutil.Run "iexplore.exe","http:\\www.gmail.com"

'Assign object property value to a variable pwd

pwd="Passwd1"

'to match up the application speed with QTP, it Waits till browser loads

Browser("title:=Gmail: Email from Google").Page("title:=Gmail: Email from Google").Sync

' Enter  Email id in Username Field

Browser("title:=Gmail: Email from Google").Page("title:=Gmail: Email from Google").WebEdit("name:=Email").Set  " QEworks.com"

'Enter password in Password Field

Browser("title:=Gmail: Email from Google").Page("title:=Gmail: Email from Google").WebEdit("name:=" & pwd).Set  pwd

'Cick on the Sign In Button

Browser("title:=Gmail: Email from Google").Page("title:=Gmail: Email from Google").WebButton("name:=Sign in").Click

 

2. Dynamic Programming: We add a collection of properties and values to a Description object, and then enter the Description object name in the statement.
    Example:

'Username="QEworks.com"

'Password="qtp"

'Login to gmail account  using  Dynamic descriptive Programing

'Launch gmail

systemutil.Run "iexplore.exe","http:\\www.gmail.com"

'Descriptive object to identify  Browser  with a particular title

Set  Dbrowser=description.Create

Dbrowser("micclass").value="Browser"

Dbrowser("title").value="Gmail: Email from Google"

'Descriptive object to identify  Web page with a particular title

Set  Dpage=description.Create

Dpage("micclass").value="Page"

Dpage("title").value="Gmail: Email from Google"

'Descriptive object to identify a  particular Web Button

Set  Dbutton=description.Create

Dbutton("micclass").value="WebButton"

button("name").value="Sign in"

'Descriptive object to identify  Web Text Box

Set Dedit=description.Create

Dedit("micclass").value="WebEdit"

Dedit("name").value="Email"

'wait till browser loads

Browser(Dbrowser).Page(Dpage).Sync 

' Enter  Email id in Username Field

Browser(Dbrowser).Page(Dpage).WebEdit(Dedit).Set  "QEworks.com"

Dedit("name").value="Passwd"

'Enter password in Passowrd Field

Browser(Dbrowser).Page(Dpage).WebEdit(Dedit).Set  "qtp"

'Click on the Sign In Button

Browser(Dbrowser).Page(Dpage).WebButton(Dbutton).Click