Labels

Monday 24 September 2012

QTP - Descriptive Programming (DP)

Driver Script

' Associate the library file via Test > Settings > Resources Tab 
'or Loading the library file from the driver script
ExecuteFile "C:\data\QTP scripts\DP_lib"

'Calling the function as simple as below
launchApp
loginApp
newOrder
enumerateAllObjects
'Main test ends here


Create a library file 'DP_lib'


'' Descriptive programming

Public Function launchApp
' Close all the existing instances of flight application
SystemUtil.CloseProcessByName "flight4a.exe"

' Launch the flight application
SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"

End Function

Public Function loginApp

' Login to the application
Dialog("regexpwndtitle:=Login").Activate
Dialog("regexpwndtitle:=Login").WinEdit("attached text:=Agent Name:").Set "Sundar"
Dialog("regexpwndtitle:=Login").WinEdit("attached text:=Password:").Set "mercury"
Dialog("regexpwndtitle:=Login").WinButton("text:=OK").Click

'Reporting the login status to the results file
If Window("regexpwndtitle:=Flight Reservation").Exist(10) Then
reporter.ReportEvent micPass, "Is Login Successful","Logged in successfully"
Else
reporter.ReportEvent micFail, "Is Login Successful","Login failed"
End If

End Function

Public Function newOrder

Window("regexpwndtitle:=Flight Reservation").Activate
' Use of  'With'- Try to use With often as it helps to improve the performance
With Window("regexpwndtitle:=Flight Reservation")
.Activate
.WinMenu("menuobjtype:=2").Select "File;New Order"
.ActiveX("progid:=MSMask.MaskEdBox.1").Type "092012"
.WinComboBox("attached text:=Fly From:").Select "Denver"
.WinComboBox("attached text:=Fly To:").Select "London"
.WinButton("text:=FLIGHT").Click
   End with
 
End Function

Public Function enumerateAllObjects
' Description object will allow you to navigate through all child objects or particular class of child objects

' Enumerating through allChild Objects of Flight Reservation Window
    Set dpAllChilds = Description.Create
Set allChilds = Window("regexpwndtitle:=Flight Reservation").ChildObjects(dpAllChilds)
iCount= allChilds.Count -1
reporter.ReportEvent micInfo, "Total Number of child objects", iCount+1

For i=0 to iCount
reporter.ReportEvent micInfo, "Child Object:"&i, allChilds.item(i).GetTOProperty("micclass") ''''&allChilds.item(i).GetTOProperty("text")
Next

' Enumerating through WinComboBox Objects of Flight Reservation Window
Set dpWinComboBox = Description.Create
dpWinComboBox("micclass").Value = "WinComboBox"
Set allWinComboBoxChilds = Window("regexpwndtitle:=Flight Reservation").ChildObjects(dpWinComboBox)
iCount = allWinComboBoxChilds.Count
reporter.ReportEvent micInfo, "Total Number of WinComboBox objects", iCount

' Enumerating through WinEdit Objects of Flight Reservation Window
Set dpWinEdit = Description.Create
dpWinEdit("micclass").Value = "WinEdit"
Set dpWinEditChilds = Window("regexpwndtitle:=Flight Reservation").ChildObjects(dpWinEdit)
iCount = dpWinEditChilds.Count
reporter.ReportEvent micInfo, "Total Number of WinComboBox objects", iCount

End Function


No comments:

Post a Comment