Error Handling and Debugging Tests in UFT

Error Handling and Debugging Tests in UFT

1) Error Handling using VBScript:

Handling expected and unexpected errors.

Expected Errors
 

Whenever we use invalid input then we expect errors.

Note: We use invalid input for negative testing.
------------------
Unexpected Errors
 

i) Resource Missing

ii) Resource Response

iii) Insufficient Resource.
---------------------------------
How to handle Errors
 

i) Using Conditional statements

ii) Using Built in 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 with multiple instance 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 instance is Zero, oldest one index is n-1

We can work with multiple browsers using "CreationTime" property,
Latest browser creation time is n-1.
-------------------------------------------------
ii) Using VBScript built in 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: 10 digits)

Range (21 to 35 Years)
-------------------------
Type & Size (Phone number object has to accept 10 digit numeric values)

Type & Range (Age object has to accept numeric value in between 21 and 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 and 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 = 5 To 10 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 only 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 only exist"
Exit Do
End If
ord = ord + 1
Loop
---------------------------------
iv) Option Explicit Statement
 

It forces declaration of all variables in a script, so that we can 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 any error is there, don't stop the script execution, skip the error and continue.

When to Choose:

If there is no impact on Final output then we can use 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 any impact on Final output then don't use it.

On Error Resume Next
Dim a, b
a=10
b-20
Msgbox a + b
----------------------------------------------
2) Debugging Tests:

i) What is Debugging?
 

Locating and isolating Errors through step by step execution.

Note: Debugging is optional in Test Automation.

ii) When Debugging is required?
 

Scenario 1:

Test is not showing any errors and providing correct output - Not required.

Scenario 2:

Test is showing any errors- Debugging optional.

Scenario 3:

Test is not showing any errors and Not providing correct output - Debugging is required.
----------------------------------------------------
Whenever Test Script is not showing any errors and not providing correct output, then debugging is required.

iii) How to debug Tests?
 

Using Debug commands and Breakpoints we can debug Tests.

Important Debug Commands:

a) Step into (F11)
    1) It starts the execution.
    2) It executes one statement at a time.
    3) If it is Function call, opens the function and executes one statement at a time.

b) Step Over (F10)
    1) It executes one statement at a time.
    2) It executes all function statements at a time.

c) Step Out (Shift + F11)
    1) It executes all reaming function statements at a time.

------------
Breakpoint (F9)

It pause 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 pause the Script execution.

Test Script Execution:

a) At a Time Execution (Using Run Command)

b) Step by Step execution (Using Debug Commands)

c) Hybrid Execution (Using Run/Continue command, debug Commands and Breakpoints)

------------------------------------

0 comments:

Post a Comment