Facebook

Course Name Start Date Time Duration Registration Link
No Training Programs Scheduled ClickHere to Contact
Please mail To sudhakar@qtpsudhakar.com to Register for any training

Wednesday, September 16, 2009

Sample Script on Descriptive Programming

Click Here to Read About Descriptive Programming
In continuation of my old post
Descriptive Programming in QTP, I prepared this sample script for the beginners of Descriptive Programming.
Click Here to Download the script file

'This ia a sample script on Flight Reservetion Application using 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\flight4a.exe"

''*******************************************************************************
'Object Description Constants
'*******************************************************************************
'Login

Public Const Login_Dialog="text:=Login"

Set Login_Edit_AgentName=CreateObjectDescription("nativeclass:=Edit,attached text:=Agent Name:")
Set Login_Edit_Password=CreateObjectDescription("nativeclass:=Edit,attached text:=Password:")
Set Login_Btn_OK=CreateObjectDescription("nativeclass:=Button,text:=OK")

'Flight Reservation Window

Public Const FlightReservation_Window="text:=Flight Reservation"
Public Const FlightReservation_Menu= "menuobjtype:=2"
Public Const FlightReservation_OpenOrder_Menu="File;Open Order..."
Public Const FlightReservation_NewOrder_Menu="File;New Order"

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:=Edit,attached text:=Name:")
Set FlightReservation_Edit_Tickets=CreateObjectDescription("nativeclass:=Edit,attached text:=Tickets:")
Set FlightReservation_Rdb_Class=CreateObjectDescription("nativeclass:=Button,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:")

'Select Flights Dialog

Public Const FlightReservation_Dialog_FlightsTable= "text:=Flights Table"

Set FlightsTable_Lst_FlightList= CreateObjectDescription("nativeclass:=ListBox,attached text:=From")
Set FlightsTable_Btn_OK= CreateObjectDescription("nativeclass:=Button,text:=OK")

'Open Order Dialog

Public Const FlightReservation_Dialog_OpenOrder="text:=Open Order"

Set OpenOrder_ChkBtn_OrderNo=CreateObjectDescription("nativeclass:=Button,text:=&Order No.")
Set OpenOrder_Btn_OK=CreateObjectDescription("nativeclass:=Button,text:=OK")
Set OpenOrder_Edit_OrderNo=CreateObjectDescription("nativeclass:=Edit,window id:=1016")

'Flight Reservation Popup Dialog
Public Const FlightReservations_PopupDialog="text:=Flight Reservations"
Set FlightReservations_Btn_YES= CreateObjectDescription("nativeclass:=Button,text:=&Yes")

''*******************************************************************************
'Object Description Constants End
'*******************************************************************************

'#############################################################################
'Main Script Start
'#############################################################################
'Open Application
Call OpenApplication (ApplicationPath)

'Login 
Call Login("Sudhakar","Mercury")

'Insert an Order
OrderInserted=InsertOrder()

'Open Inserted Order
Call OpenOrder(OrderInserted)

'Delete Inserted Order
Call DeleteOrder (OrderInserted)

'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_DateOfFlight).Type "111111"
Window(FlightReservation_Window).WinComboBox(FlightReservation_Cmb_FlyFrom).Select "Denver"
Window(FlightReservation_Window).WinComboBox(FlightReservation_Cmb_FlyTo).Select "Frankfurt"
Window(FlightReservation_Window).WinButton(FlightReservation_Btn_Flight).Click
Window(FlightReservation_Window).Dialog(FlightReservation_Dialog_FlightsTable).WinList(FlightsTable_Lst_FlightList).Select 0
Window(FlightReservation_Window).Dialog(FlightReservation_Dialog_FlightsTable).WinButton(FlightsTable_Btn_OK).Click
Window(FlightReservation_Window).WinEdit(FlightReservation_Edit_Name).Set "sudhakar kakunuri"
Window(FlightReservation_Window).WinEdit(FlightReservation_Edit_Tickets).Set 10
Window(FlightReservation_Window).WinRadioButton(FlightReservation_Rdb_Class).Set
Window(FlightReservation_Window).WinButton(FlightReservation_Btn_InsertOrder).Click
Window(FlightReservation_Window).WinButton(FlightReservation_Btn_DeleteOrder).WaitProperty "enabled",true,10000
InsertOrder=Window(FlightReservation_Window).WinEdit(FlightReservation_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_OpenOrder).WinCheckBox(OpenOrder_ChkBtn_OrderNo).Set "ON"
Window(FlightReservation_Window).Dialog(FlightReservation_Dialog_OpenOrder).WinEdit(OpenOrder_Edit_OrderNo).Set OrderNumber
Window(FlightReservation_Window).Dialog(FlightReservation_Dialog_OpenOrder).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_DeleteOrder).Click
Window(FlightReservation_Window).Dialog(FlightReservations_PopupDialog).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,",")
 
 For PropCount=0 to ubound(ObjArr)
  ObjProperty=split(ObjArr(PropCount),":=")
  objDescription(ObjProperty(0)).value=ObjProperty(1)
 Next
 
  Set CreateObjectDescription=objDescription

End Function

'*******************************************************************************
'Functions End
'*******************************************************************************
____________________________________________________________________________
Please send your Suggestions and Doubts to my yahoo group http://in.groups.yahoo.com/group/qtpsudhakar

4 comments :

  1. Hi, I am new to QTP.Plz help meIt is showing errr after launching the application when it goes into the login fucntion at first line,showing unexpected error.At below line it is showing error.Dialog(Login_Dialog).WinEdit(Login_Edit_AgentName).Set iUserName

    ReplyDelete
  2. This function CreateObjectDescription(StrProperties) is good...helps a lot in DP framework..

    ReplyDelete
  3. Hi Sudhakar,

    I would like to thanks for sharing knowledge on QTP and VB by you, you are really doing nice job here.

    Seems that link 'Descriptive Programming in QTP' is not working, please can you update it.

    Regrds,
    OS Rathore

    ReplyDelete