Error Handling as well as Debugging Tests inwards UFT
1) Error Handling using VBScript:
Handling expected as well as unexpected errors.
Expected Errors
Whenever nosotros purpose invalid input as well as hence nosotros facial expression errors.
Note: We purpose invalid input for negative testing.
------------------
Unexpected Errors
i) Resource Missing
ii) Resource Response
iii) Insufficient Resource.
---------------------------------
How to handgrip Errors
i) Using Conditional statements
ii) Using Built inwards Functions
iii) Using Exit Statement
iv) Using Option Explicit Statement
v) Using On Error Resume Next Statement etc...
------------------------------------------------
Examples:
i) Using Conditional Statements
If Not Dialog("Login").Exist(3) Then
SystemUtil.Run "C:\Program Files\HP\Unified Functional Testing\samples\flight\app\flight4a.exe"
End If
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set "asdf"
Dialog("Login").WinEdit("Password:").SetSecure "568f197c413764022c3007b08119c8a51bee9d09"
Dialog("Login").WinButton("OK").Click
--------------------------------------
Working amongst multiple event of Application
SystemUtil.Run "C:\Program Files\HP\Unified Functional Testing\samples\flight\app\flight4a.exe"
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 "568f197c413764022c3007b08119c8a51bee9d09"
Dialog("text:=Login", "index:=0").WinButton("text:=OK").Click
-----------------------------------------------
Note:
Latest Application event is Zero, oldest 1 index is n-1
We tin give the axe function amongst multiple browsers using "CreationTime" property,
Latest browser creation fourth dimension is n-1.
-------------------------------------------------
ii) Using VBScript built inwards Functions
Dim num1, num2
num1= Cint (InputBox("Enter num1 value"))
num2= Cint (InputBox("Enter num2 value"))
Msgbox "Addition of num1, num2 is "& num1 + num2
-------------------------------------
Dim num1, num2
num1= InputBox("Enter num1 value")
num2= InputBox("Enter num2 value")
If IsNumeric(num1) = True And IsNumeric(num2) =True Then
Msgbox "Addition of num1, num2 is: "& Cint(num1) + Cint(num2)
Else
Msgbox "Invalid Input"
End If
---------------------------------------------------------
Data factors
-------------
Type (Ex: Numeric)
Size (Ex: ten digits)
Range (21 to 35 Years)
-------------------------
Type & Size (Phone publish object has to convey ten digit numeric values)
Type & Range (Age object has to convey numeric value inwards betwixt 21 as well as 35)
-------------------------------
'Handling Range of Data
Dim Age
Age = InputBox("Enter Age")
If Age >= 21 And Age <= 35 Then
Msgbox "Valid Data"
Else
Msgbox "Invalid Data"
End If
-----------------------------
'Handling Range as well as Type
Dim Age
Age = InputBox("Enter Age")
If IsNumeric(Age) = True Then
If Age >= 21 And Age <= 35 Then
Msgbox "Valid Data"
Else
Msgbox "Invalid Data"
End If
Else
Msgbox "Invalid Data"
End If
---------------------------------------------
iii) using Exit Statement
Exit Statement is used to terminate Loops (ex: Exit For, Exit Do)
Example:
'Terminating For Loop
For ord = v To ten 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 ord
wait 2
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
Window("Flight Reservation").WinButton("Button_2").Click
Reporter.ReportEvent micWarning, "Res", "Up to "& ord-1 & " Orders solely exist"
Exit For
End If
Next
--------------------------------------
'Terminating Do Loop
ord = 25
Do Until ord >= 30
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 ord
wait 2
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
Window("Flight Reservation").WinButton("Button_2").Click
Reporter.ReportEvent micWarning, "Res", "Up to "& ord-1 & " Orders solely exist"
Exit Do
End If
ord = ord + 1
Loop
---------------------------------
iv) Option Explicit Statement
It forces proclamation of all variables inwards a script, hence that nosotros tin give the axe avoid miss-spell problems
Option Explicit
Dim Tickets, Price, Total
Tickets = 7
Price = 100
Total = Tickets * Price
Msgbox Total
----------------------------------------
v) Using "On Error Resume Next" Statement
If whatever mistake is there, don't cease the script execution, skip the mistake as well as continue.
When to Choose:
If in that place is no comport upon on Final output as well as hence nosotros tin give the axe purpose it.
On Error Resume Next
VbWindow("Form1").Activate
VbWindow("Form1").VbComboBox("Combo1").Select "Chennai"
VbWindow("Form1").VbComboBox("Combo1").Select "Goa"
VbWindow("Form1").VbComboBox("Combo1").Select "Hyderabad"
VbWindow("Form1").VbComboBox("Combo1").Select "New Delhi"
VbWindow("Form1").VbComboBox("Combo1").Select "Mumbai"
When Not to use:
If whatever comport upon on Final output as well as hence don't purpose it.
On Error Resume Next
Dim a, b
a=10
b-20
Msgbox a + b
----------------------------------------------
2) Debugging Tests:
i) What is Debugging?
Locating as well as isolating Errors through pace yesteryear pace execution.
Note: Debugging is optional inwards Test Automation.
ii) When Debugging is required?
Scenario 1:
Test is non showing whatever errors as well as providing right output - Not required.
Scenario 2:
Test is showing whatever errors- Debugging optional.
Scenario 3:
Test is non showing whatever errors as well as Not providing right output - Debugging is required.
----------------------------------------------------
Whenever Test Script is non showing whatever errors as well as non providing right output, as well as hence debugging is required.
iii) How to debug Tests?
Using Debug commands as well as Breakpoints nosotros tin give the axe debug Tests.
Important Debug Commands:
a) Step into (F11)
1) It starts the execution.
2) It executes 1 contestation at a time.
3) If it is Function call, opens the component as well as executes 1 contestation at a time.
b) Step Over (F10)
1) It executes 1 contestation at a time.
2) It executes all component statements at a time.
c) Step Out (Shift + F11)
1) It executes all reaming component statements at a time.
------------
Breakpoint (F9)
It interruption the Script execution.
--------------------------------------------
Example:
Dim a, b, c
a =10
b =20
c= a+b
a =1
b =3
c= a*b
Call Login("abcd", "mercury")
a =100
b =200
c= a-b
a =15
b =35
c= a/b
a=100
---------------------------------
Breakpoint (F9)
It interruption the Script execution.
Test Script Execution:
a) At a Time Execution (Using Run Command)
b) Step yesteryear Step execution (Using Debug Commands)
c) Hybrid Execution (Using Run/Continue command, debug Commands as well as Breakpoints)
------------------------------------
Sumber http://www.gcreddy.com/
1) Error Handling using VBScript:
Handling expected as well as unexpected errors.
Expected Errors
Whenever nosotros purpose invalid input as well as hence nosotros facial expression errors.
Note: We purpose invalid input for negative testing.
------------------
Unexpected Errors
i) Resource Missing
ii) Resource Response
iii) Insufficient Resource.
---------------------------------
How to handgrip Errors
i) Using Conditional statements
ii) Using Built inwards Functions
iii) Using Exit Statement
iv) Using Option Explicit Statement
v) Using On Error Resume Next Statement etc...
------------------------------------------------
Examples:
i) Using Conditional Statements
If Not Dialog("Login").Exist(3) Then
SystemUtil.Run "C:\Program Files\HP\Unified Functional Testing\samples\flight\app\flight4a.exe"
End If
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set "asdf"
Dialog("Login").WinEdit("Password:").SetSecure "568f197c413764022c3007b08119c8a51bee9d09"
Dialog("Login").WinButton("OK").Click
--------------------------------------
Working amongst multiple event of Application
SystemUtil.Run "C:\Program Files\HP\Unified Functional Testing\samples\flight\app\flight4a.exe"
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 "568f197c413764022c3007b08119c8a51bee9d09"
Dialog("text:=Login", "index:=0").WinButton("text:=OK").Click
-----------------------------------------------
Note:
Latest Application event is Zero, oldest 1 index is n-1
We tin give the axe function amongst multiple browsers using "CreationTime" property,
Latest browser creation fourth dimension is n-1.
-------------------------------------------------
ii) Using VBScript built inwards Functions
Dim num1, num2
num1= Cint (InputBox("Enter num1 value"))
num2= Cint (InputBox("Enter num2 value"))
Msgbox "Addition of num1, num2 is "& num1 + num2
-------------------------------------
Dim num1, num2
num1= InputBox("Enter num1 value")
num2= InputBox("Enter num2 value")
If IsNumeric(num1) = True And IsNumeric(num2) =True Then
Msgbox "Addition of num1, num2 is: "& Cint(num1) + Cint(num2)
Else
Msgbox "Invalid Input"
End If
---------------------------------------------------------
Data factors
-------------
Type (Ex: Numeric)
Size (Ex: ten digits)
Range (21 to 35 Years)
-------------------------
Type & Size (Phone publish object has to convey ten digit numeric values)
Type & Range (Age object has to convey numeric value inwards betwixt 21 as well as 35)
-------------------------------
'Handling Range of Data
Dim Age
Age = InputBox("Enter Age")
If Age >= 21 And Age <= 35 Then
Msgbox "Valid Data"
Else
Msgbox "Invalid Data"
End If
-----------------------------
'Handling Range as well as Type
Dim Age
Age = InputBox("Enter Age")
If IsNumeric(Age) = True Then
If Age >= 21 And Age <= 35 Then
Msgbox "Valid Data"
Else
Msgbox "Invalid Data"
End If
Else
Msgbox "Invalid Data"
End If
---------------------------------------------
iii) using Exit Statement
Exit Statement is used to terminate Loops (ex: Exit For, Exit Do)
Example:
'Terminating For Loop
For ord = v To ten 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 ord
wait 2
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
Window("Flight Reservation").WinButton("Button_2").Click
Reporter.ReportEvent micWarning, "Res", "Up to "& ord-1 & " Orders solely exist"
Exit For
End If
Next
--------------------------------------
'Terminating Do Loop
ord = 25
Do Until ord >= 30
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 ord
wait 2
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
Window("Flight Reservation").WinButton("Button_2").Click
Reporter.ReportEvent micWarning, "Res", "Up to "& ord-1 & " Orders solely exist"
Exit Do
End If
ord = ord + 1
Loop
---------------------------------
iv) Option Explicit Statement
It forces proclamation of all variables inwards a script, hence that nosotros tin give the axe avoid miss-spell problems
Option Explicit
Dim Tickets, Price, Total
Tickets = 7
Price = 100
Total = Tickets * Price
Msgbox Total
----------------------------------------
v) Using "On Error Resume Next" Statement
If whatever mistake is there, don't cease the script execution, skip the mistake as well as continue.
When to Choose:
If in that place is no comport upon on Final output as well as hence nosotros tin give the axe purpose it.
On Error Resume Next
VbWindow("Form1").Activate
VbWindow("Form1").VbComboBox("Combo1").Select "Chennai"
VbWindow("Form1").VbComboBox("Combo1").Select "Goa"
VbWindow("Form1").VbComboBox("Combo1").Select "Hyderabad"
VbWindow("Form1").VbComboBox("Combo1").Select "New Delhi"
VbWindow("Form1").VbComboBox("Combo1").Select "Mumbai"
When Not to use:
If whatever comport upon on Final output as well as hence don't purpose it.
On Error Resume Next
Dim a, b
a=10
b-20
Msgbox a + b
----------------------------------------------
2) Debugging Tests:
i) What is Debugging?
Locating as well as isolating Errors through pace yesteryear pace execution.
Note: Debugging is optional inwards Test Automation.
ii) When Debugging is required?
Scenario 1:
Test is non showing whatever errors as well as providing right output - Not required.
Scenario 2:
Test is showing whatever errors- Debugging optional.
Scenario 3:
Test is non showing whatever errors as well as Not providing right output - Debugging is required.
----------------------------------------------------
Whenever Test Script is non showing whatever errors as well as non providing right output, as well as hence debugging is required.
iii) How to debug Tests?
Using Debug commands as well as Breakpoints nosotros tin give the axe debug Tests.
Important Debug Commands:
a) Step into (F11)
1) It starts the execution.
2) It executes 1 contestation at a time.
3) If it is Function call, opens the component as well as executes 1 contestation at a time.
b) Step Over (F10)
1) It executes 1 contestation at a time.
2) It executes all component statements at a time.
c) Step Out (Shift + F11)
1) It executes all reaming component statements at a time.
------------
Breakpoint (F9)
It interruption the Script execution.
--------------------------------------------
Example:
Dim a, b, c
a =10
b =20
c= a+b
a =1
b =3
c= a*b
Call Login("abcd", "mercury")
a =100
b =200
c= a-b
a =15
b =35
c= a/b
a=100
---------------------------------
Breakpoint (F9)
It interruption the Script execution.
Test Script Execution:
a) At a Time Execution (Using Run Command)
b) Step yesteryear Step execution (Using Debug Commands)
c) Hybrid Execution (Using Run/Continue command, debug Commands as well as Breakpoints)
------------------------------------