Professional Documents
Culture Documents
com
www.gcreddy.com
www.gcreddy.net
Providing Objects information directly into the Test Script, instead of storing objects
information in the Object Repository.
Tests using Descriptive programming are faster than Tests using Object Repository
If the AUT (Application Under Test) is having Dynamic Objects, then it is better to use
descriptive programming. Incase of object repository, it is Difficult to handle dynamic
Objects.
Descriptive Programming is useful if the AUT is having objects that are adding in the Run
Time. We can’t add Objects to Object Repository in run time.
Descriptive Programming is useful, if the AUT is having similar type of objects or similar
name objects. Incase of Object Repository, It will create multiple objects with same
description unnecessarily.
Tests using Descriptive Programming can be executed in any version of QTP without any
changes.
Code Portability: Just code is enough to run Tests. We can copy and paste in other scripts
for any other required requirement.
Reusing of Properties: We can assign properties to a global variable and reuse it for same
type of objects.
Plug & Play: Any time Tests will be in ready to run state. No need to worry about any
other settings or files.
Just Maintenance of variables: We can store the object properties in the form of variables
in a txt / vbs file which will be placed in central location. In this case we just need to
maintain that file.
1) Static: - We enter the set of properties and values that describe the object directly in
a VBScript statement.
Browser(“micclass:=Browser”).Page(micclass:=page”).Link(“name:=gcreddy”).Click
g_MainBrowser =“micclass:=Browser”
g_MainPage =“micclass:=Page”
g_Lnk_Login =“name:=Login”
Browser(g_MainBrowser).Page(g_MainPage).Link(g_Lnk_Login).Click
Browser(oBrowser).Page(oPage).Link(oLink).click
Using the Static type to enter programmatic descriptions directly into your statements
may be easier for basic object description needs. However, in most cases, using the
Dynamic type provides more power, efficiency, and flexibility.
Same Description Objects : Property values are same for multiple objects.
Runtime Added Object : Object is not there in recording time but it might be add in
runtime.
Ex: Always the job links in Naukri and Monster sites will get update.
Child object method is very useful to get control on Runtime added objects or dynamic
objects or same description objects which are there application.
Ex1: If there are multiple signin links on the page, using child objects method we can click
on any signin link.
Dim oLinkDescription
Dim oLinks
Dim lnkCount
Set oLinkDescription=Description.Create
oLinkDescription("name").value="signin"
set
oLinks=browser("micclass:=Browser").page("micclass:=Page").ChildObject
s(oLinkDescription)
oLinks(0).click
End If
‘***********************************************************
This code will click on the first signin link. To click on second signin link
replace ‘oLinks(0).click to oLinks(1).click in ‘if’ condition. In the same
manner if any object properties are changed we can get index of the object
using childobjects method.
Set oButtonDescription=Description.Create
oButtonDescription ("micclass").value="Button"
set
oButtons=browser("micclass:=Browser").page("micclass:=Page").ChildObj
ects(oButtonDescription)
The above code will highlight all buttons in the page. This will make easy to
identify the index of the button. Using index we can easily click on the
button.
‘Static
To use these constants in your script always it’s a good practice to follow is
Keep these constants in a vbs file and associate to your QTP Test.
‘Dynamic
If you’re going for dynamic the only problem is repetitive code. Every time
we need use description.create which leads to more maintenance. There
are three objects and if we want to use multiple properties for those
objects we need to write description.create for three times.
Solution:
Set LoginPage_Button_Login =
CreateObjectDescription(“name:=Login,type:=submit”)
‘***********************************************************
*******
Function CreateObjectDescription(StrProperties)
Dim objDescription
Dim ObjArr
Dim PropCount
Dim ObjProperty
Set objDescription=Description.Create
ObjArr=split(StrProperties,",")
Set CreateObjectDescription=objDescription
End Function
‘***********************************************************
*******
This function gives a way to use multiple properties for any number of
objects with less code maintenance. But the only one rule is we need follow
is ‘set’ statement. Because the return value of the function
CreateObjectDescription is a description object. To store any object in a
variable we need to use ‘Set” statement.
The parameter which you pass to the function should be in string format.
Ex:‘Acceptable
Here the hierarchy is Test Object to Descriptive. Browser and page are
representing Object Repository names and the link is taking description.
‘Not acceptable
Browser(“micclass:=Browser”).Page(OR
LogicalName).Link(“name:Login”).click
Or
Browser(“micclass:=Browser”).Page(“micclass:=Page”).).Link(OR
LogicalName).click
This means that from the point where you have started giving description
to the objects in a statement, you must continue giving description to the
total objects in that hierarchy.
Ex1:
Public const LoginPage_Edit_UserName = “name:=UserName.*”
Ex2:
Browser(“micclass:=Browser”).Page(micclass:=page”).Link(“name:=Login.
*”).Click
Ex3:
Set oLink = Description.create
oLink (“name”).value= “Login.*”
oLink (“index”).value= 1
Browser(“micclass:=Browser”).Page(micclass:=page”).Link(oLink).click
Descriptive Programming
'Script Flow :- Open Flight Reservation Application --> Login --> Insert
Order --> Open Order --> Delete Order
'Object Descriptions created in the script by using
CreateObjectDescription Function.
'If object is using only one property then i have created a constant for
it.
'*********************************************************
**********************
'Input Variables
'*********************************************************
**********************
Dim ApplicationPath
ApplicationPath=Environment("ProductDir")&"\samples\flight\app\flight4
a.exe"
'*********************************************************
**********************
'Object Description Constants
'*********************************************************
**********************
'Login
Set
Login_Edit_AgentName=CreateObjectDescription("nativeclass:=Edit,att
ached text:=Agent Name:")
Set
Login_Edit_Password=CreateObjectDescription("nativeclass:=Edit,attac
hed text:=Password:")
Set
Login_Btn_OK=CreateObjectDescription("nativeclass:=Button,text:=OK
")
Set FlightReservation_Obj_DateOfFlight=
CreateObjectDescription("nativeclass:=MSMaskWndClass,attached
text:=Date of Flight:")
Set FlightReservation_Cmb_FlyFrom=
CreateObjectDescription("nativeclass:=ComboBox,attached text:=Fly
From:")
Set FlightReservation_Cmb_FlyTo=
CreateObjectDescription("nativeclass:=ComboBox,attached text:=Fly
To:")
Set FlightReservation_Btn_Flight=
CreateObjectDescription("nativeclass:=Button,text:=FLIGHT")
Set
FlightReservation_Edit_Name=CreateObjectDescription("nativeclass:=E
dit,attached text:=Name:")
Set
FlightReservation_Edit_Tickets=CreateObjectDescription("nativeclass:=
Edit,attached text:=Tickets:")
Set
FlightReservation_Rdb_Class=CreateObjectDescription("nativeclass:=Bu
tton,text:=First")
Set FlightReservation_Btn_InsertOrder=
CreateObjectDescription("nativeclass:=Button,text:=&Insert Order")
Set FlightReservation_Btn_UpdateOrder=
CreateObjectDescription("nativeclass:=Button,text:=&Update Order")
Set FlightReservation_Btn_DeleteOrder=
CreateObjectDescription("nativeclass:=Button,text:=&Delete Order")
Set
FlightReservation_Edit_OrderNo=CreateObjectDescription("nativeclass:
=Edit,attached text:=Order No:")
Set FlightsTable_Lst_FlightList=
CreateObjectDescription("nativeclass:=ListBox,attached text:=From")
Set FlightsTable_Btn_OK=
CreateObjectDescription("nativeclass:=Button,text:=OK")
Set
OpenOrder_ChkBtn_OrderNo=CreateObjectDescription("nativeclass:=Bu
tton,text:=&Order No.")
Set
OpenOrder_Btn_OK=CreateObjectDescription("nativeclass:=Button,text
:=OK")
Set
OpenOrder_Edit_OrderNo=CreateObjectDescription("nativeclass:=Edit,
window id:=1016")
''********************************************************
***********************
'Object Description Constants End
'*********************************************************
**********************
'############################################
#################################
'Main Script Start
'############################################
#################################
'Open Application
Call OpenApplication (ApplicationPath)
'Login
Call Login("Sudhakar","Mercury")
'Insert an Order
OrderInserted=InsertOrder()
'Close Application
Call CloseApplication()
'############################################
#################################
'Main Script End
'############################################
#################################
'Functions Start
'*********************************************************
**********************
Function OpenApplication(AppPath)
InvokeApplication AppPath
End Function
'*********************************************************
**********************
'*********************************************************
**********************
Function Login(iUserName,iPassword)
Dialog(Login_Dialog).WinEdit(Login_Edit_AgentName).Set iUserName
Dialog(Login_Dialog).WinEdit(Login_Edit_Password).Set iPassword
Dialog(Login_Dialog).WinButton(Login_Btn_OK).Click
If err.Description="" Then
Reporter.ReportEvent micPass,"Login","Login Successful"
Else
Reporter.ReportEvent micFail,"Login","Login Failed"
End If
End Function
'*********************************************************
**********************
'*********************************************************
**********************
Function InsertOrder()
Window(FlightReservation_Window).WinMenu(FlightReservation_Menu).
Select FlightReservation_NewOrder_Menu
Window(FlightReservation_Window).WinObject(FlightReservation_Obj_D
ateOfFlight).Type "111111"
Window(FlightReservation_Window).WinComboBox(FlightReservation_C
mb_FlyFrom).Select "Denver"
Window(FlightReservation_Window).WinComboBox(FlightReservation_C
mb_FlyTo).Select "Frankfurt"
Window(FlightReservation_Window).WinButton(FlightReservation_Btn_Fl
ight).Click
Window(FlightReservation_Window).Dialog(FlightReservation_Dialog_Fli
ghtsTable).WinList(FlightsTable_Lst_FlightList).Select 0
Window(FlightReservation_Window).Dialog(FlightReservation_Dialog_Fli
ghtsTable).WinButton(FlightsTable_Btn_OK).Click
Window(FlightReservation_Window).WinEdit(FlightReservation_Edit_Na
me).Set "sudhakar kakunuri"
Window(FlightReservation_Window).WinEdit(FlightReservation_Edit_Tick
ets).Set 10
Window(FlightReservation_Window).WinRadioButton(FlightReservation_
Rdb_Class).Set
Window(FlightReservation_Window).WinButton(FlightReservation_Btn_I
nsertOrder).Click
Window(FlightReservation_Window).WinButton(FlightReservation_Btn_D
eleteOrder).WaitProperty "enabled",true,10000
InsertOrder=Window(FlightReservation_Window).WinEdit(FlightReservat
ion_Edit_OrderNo).GetROProperty("text")
If err.Description="" Then
Reporter.ReportEvent micPass,"Insert Order","Order Inserted
Successfully"
Else
Reporter.ReportEvent micFail,"Insert Order","Failed in Inserting an
Order"
End If
End Function
'*********************************************************
**********************
'*********************************************************
**********************
Function OpenOrder(OrderNumber)
Window(FlightReservation_Window).WinMenu(FlightReservation_Menu).
Select FlightReservation_OpenOrder_Menu
Window(FlightReservation_Window).Dialog(FlightReservation_Dialog_Op
enOrder).WinCheckBox(OpenOrder_ChkBtn_OrderNo).Set "ON"
Window(FlightReservation_Window).Dialog(FlightReservation_Dialog_Op
enOrder).WinEdit(OpenOrder_Edit_OrderNo).Set OrderNumber
Window(FlightReservation_Window).Dialog(FlightReservation_Dialog_Op
enOrder).WinButton(OpenOrder_Btn_OK).Click
If err.Description="" Then
Reporter.ReportEvent micPass,"Open Order","Order Opened
Successfully"
Else
Reporter.ReportEvent micFail,"Open Order","Failed in Opening an
Order"
End If
End Function
'*********************************************************
**********************
'*********************************************************
**********************
Function DeleteOrder(OrderNumber)
Call OpenOrder(OrderNumber)
Window(FlightReservation_Window).WinButton(FlightReservation_Btn_D
eleteOrder).Click
Window(FlightReservation_Window).Dialog(FlightReservations_PopupDia
log).WinButton(FlightReservations_Btn_YES).Click
If err.Description="" Then
Reporter.ReportEvent micPass,"Delete Order","Order Deleted
Successfully"
Else
Reporter.ReportEvent micFail,"Delete Order","Failed in Deleting an
Order"
End If
End Function
'*********************************************************
**********************
'*********************************************************
**********************
Function CloseApplication()
Window(FlightReservation_Window).Close
If err.Description="" Then
Reporter.ReportEvent micPass,"Close Application","Application
Closed Successfully"
Else
Reporter.ReportEvent micFail,"Close Application","Failed in Closing
the Application"
End If
End Function
'*********************************************************
**********************
'*********************************************************
**********************
Function CreateObjectDescription(StrProperties)
Dim objDescription
Dim ObjArr
Dim PropCount
Dim ObjProperty
Set objDescription=Description.Create
ObjArr=split(StrProperties,",")
Set CreateObjectDescription=objDescription
End Function
'*********************************************************
**********************
'Functions End
www.gcreddy.com