Description Object in QTP (Description. Create)

We will look at Description Objects (Description. Create in QTP) which is very important in Descriptive programming in QTP. In Descriptive programming we can create object with description being a single property or multiple properties. We actually put a collection of properties for an object. We can create and empty object and place all the required properties in it. This object can be used instead of the actual object.


We will see how to create a Description Object

Set Desc = Description.Create

We are actually using a variable called Desc and add properties to the variable using the Description.Create method. The variable Desc should follow a Set statement and the variable Des is an object reference.

Let us look at the Flight Reservation Application and create some Description objects for logging in to the Flight Reservation Application.


'script to login flight reservation using dynamic descriptive programming

Set dialog_login = Description.create
dialog_login("text").value ="Login"

Set edit_agentname = Description.Create
edit_agentname("attached text").value = "Agent Name:"

Set edit_password = Description.Create
edit_password("attached text").value = "Password:"

Set button_ok = Description.Create
button_ok("text").value ="OK"

Dialog(dialog_login).Activate
Dialog(dialog_login).WinEdit(edit_agentname).Set "Ravi"
Dialog(dialog_login).WinEdit(edit_password).Set "mercury"
Dialog(dialog_login).WinButton(button_ok).Click

In the above code we are actually using the properties and values and creating the objects and using them instead of the actual objects. This kind of method is very easy and maintainable because there is always a scope of adding new properties and values to the Description objects.

The other way to login in to the Flight Reservation Application is by simply putting in the properties and values in the script it self instead of creating description Objects. Instead of learning the objects into the object repository we use the associated properties and values of the object and directly pass them.

Look at the simple script using descriptive programming.

'Descriptive programming to login to the flight application.

Dialog("text:=Login").Activate
Dialog("text:=Login").WinEdit("attached text:=Agent Name:").Set "Ravi"
Dialog("text:=Login").WinEdit("attached text:=Password:").Set "mercury"
Dialog("text:=Login").WinButton("text:=OK").Click

6 comments:

jaya said...

Why test is used for Dialog box 'login' while attached text is used for Agent name and password?again why text is used for button ok?please help me in understanding it.

Anonymous said...

if i have to create a script for gmail login,
how can i use Description.create() for it

Ankita

Maheswar.Sadhu said...

text, attached text are properties of components

qtp tester said...

text is the property for the dialog method . for list of the properties use object spy . open object spy and click on hand pointer icon and select the object which u want to know the properties .

qtp tester said...

Set d_l = Description.create
d_l("title").value ="Google"

set p_l = Description.create
p_l("title").value = "Google"

Set edit_username = Description.Create
edit_username("name").value = "Username"

Set edit_password = Description.Create
edit_password("name").value = "Password"

Set button_ok = Description.Create
button_ok("name").value ="Sign in"

invoke application "C:\program files\Internet Explorer\iexplore.exe"
browser("title:=about:blank").Navigate "http://gmail.com"

browser(d_l).page(p_l).webedit(edit_username).set "give some username"
browser(d_l).page(p_l).webedit(edit_password).set "give password"
browser(d_l).page(p_l).webbutton(button_ok).click

Kanikaram Kiranpaul said...

Hi Guyz, Thanks a lot for your comments.
@qtp tester thanks for the script.
When i have written these scripts and now when we see Gmail there are lot of changes in the objects and their properties. So this script should be modified.

Post a Comment

/* Tynt Insight tracker ----------------------------------------------- */