Exception Handling in qtp

Exception Handling

—————

Using Conditional statements
Using Exist Property
Using Exit Statement
Using On Error Resume Next
Using Recovery Scenarios (QTP)

————————————-

Examples:
 —————
 Exist Property


If Not Dialog(“Login”).Exist(3) Then
SystemUtil.Run “C:Program FilesHPQuickTest Professionalsamplesflightappflight4a.exe”,””,”C:Program FilesHPQuickTest Professionalsamplesflightapp”,”open”
End If
Dialog(“Login”).Activate
Dialog(“Login”).WinEdit(“Agent Name:”).Set “asdf”
Dialog(“Login”).WinEdit(“Password:”).SetSecure “4f1eab499e54b7dafa09332c412708495ac0ca84″
Dialog(“Login”).WinButton(“OK”).Click
——————————————–
SystemUtil.Run “C:Program FilesHPQuickTest Professionalsamplesflightappflight4a.exe”,””,”C:Program FilesHPQuickTest Professionalsamplesflightapp”,”open”
Dialog(“text:=Login”,”index:=0″).Activate
Dialog(“text:=Login”,”index:=0″).WinEdit(“attached text:=Agent Name:”).Set “asdf”
Dialog(“text:=Login”,”index:=0″).WinEdit(“attached text:=Password:”).SetSecure “4f1eab499e54b7dafa09332c412708495ac0ca84″
Dialog(“text:=Login”,”index:=0″).WinButton(“text:=OK”).Click
—————————————————————-
Dim oObject, Objects
Set oObject = Description.Create
oObject(“Class Name”).value =”Dialog”
Set Objects = Desktop.ChildObjects(oObject)
For i = 1 to Objects.Count -1 Step 1
Objects(i).Close
Next
SystemUtil.Run “C:Program FilesHPQuickTest Professionalsamplesflightappflight4a.exe”,””,”C:Program FilesHPQuickTest Professionalsamplesflightapp”,”open”
Dialog(“text:=Login”,”index:=0″).Activate
Dialog(“text:=Login”,”index:=0″).WinEdit(“attached text:=Agent Name:”).Set “asdf”
Dialog(“text:=Login”,”index:=0″).WinEdit(“attached text:=Password:”).SetSecure “4f1eab499e54b7dafa09332c412708495ac0ca84″
Dialog(“text:=Login”,”index:=0″).WinButton(“text:=OK”).Click
———————————————————–
Dim oObject, Objects
Set oObject = Description.Create
oObject(“micclass”).value =”Browser”
Set Objects = Desktop.ChildObjects(oObject)
For i = 0 to Objects.Count -1 Step 1
Objects(i).Close
Next
SystemUtil.Run “C:Program FilesInternet Exploreriexplore.exe”,”www.google.com”
Browser(“CreationTime:=0″).Page(“title:=Google”).Link(“text:=Gmail”).Click
———————————————————
Exit Statement
—————–

For i = 15 to 20 Step 1
Window(“Flight Reservation”).Activate
Window(“Flight Reservation”).WinButton(“Button”).Click
Window(“Flight Reservation”).Dialog(“Open Order”).WinCheckBox(“Order No.”).Set “ON”
Window(“Flight Reservation”).Dialog(“Open Order”).WinEdit(“Edit”).Set i
Window(“Flight Reservation”).Dialog(“Open Order”).WinButton(“OK”).Click

If  Window(“Flight Reservation”).Dialog(“Open Order”).Dialog(“Flight Reservations”).Exist(3) Then
Window(“Flight Reservation”).Dialog(“Open Order”).Dialog(“Flight Reservations”).WinButton(“OK”).Click
Window(“Flight Reservation”).Dialog(“Open Order”).WinButton(“Cancel”).Click
Reporter.ReportEvent micWarning,”Res1″,”Up to “&i-1 & ” Orders only Exist”
Exit For
End If

Next

——————————————————————–
On Error Resume Next Statement
——————————-
On Error Resume Next (Not to use)
Dim num1, num2, sum
num1=100
num2-200
sum=num1+num2
Msgbox sum

 

Comments