UFT Tutorial 36


UFT Class 36 (UFT Error Handling Part-1)
---------------------
Handling Expected and Unexpected Errors is called Error Handling.

Expected Errors:
------------------
Whenever we use invalid input then we can expect errors.

Why we need to use Invalid input?

We use invalid input for negative Testing.

Unexpected Errors:---------------------
i) Resource response:

ii) Insufficient Resource:

iii) Availability of the Resource:
etc...
--------------------------------------------
How to handle Errors?
i) Using Conditional Statements.

ii) Using some built in functions.

iii) Using Option Explicit statement

iv) Using Exit statement

v) Using On Error Resume Next statement

vi) Recovery Scenarios (UFT Tool feature)

Etc...
-------------------------------------------
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 "abcd"
Dialog("Login").WinEdit("Password:").SetSecure "55305d8c4ad0885ad2cc27ad15a8a30755825bff"
Dialog("Login").WinButton("OK").Click
---------------------------------------------
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 "abcd"
Dialog("text:=Login", "index:=0").WinEdit("attached text:=Password:").SetSecure "55305d8c4ad0885ad2cc27ad15a8a30755825bff"
Dialog("text:=Login", "index:=0").WinButton("text:=OK").Click
-------------------------------------------------------------
ii) Using some built in functions.
Dim a, b
a = InputBox ("Enter A value")
b = Inputbox("Enter B value")
Msgbox Cdbl (a) + Cdbl (b)
-------------------------------
Dim a, b
a = InputBox ("Enter A value")
b = Inputbox("Enter B value")

If IsNumeric(a) = True and IsNumeric(b) = True Then
    Msgbox Cdbl (a) + Cdbl (b)
    Else
    Msgbox "Invalid Input"
End If
-----------------------------------------
iii) Using Option Explicit statement
Option Explicit
Dim Tickets, Price, Total
Tickets = 7
Price = 100
Total = Tickets * Price
Msgbox Total
--------------------------------------
iv) Using Exit statement
For OrderNumer = 1 To 5 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 OrderNumer
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 3, "Res1", "Up to: "& OrderNumer-1 & " Orders only Exists"
Exit For
End If
Next
-------------------------------------
OrderNumer = 15
Do Until OrderNumer > 20
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 OrderNumer
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 3, "Res1", "Up to: "& OrderNumer-1 & " Orders only Exists"
Exit Do
End If
OrderNumer = OrderNumer + 1
Loop
----------------------------------------------------
v) Using On Error Resume Next statement
If any error is there, skip the error and continue the Execution.

> When to choose:

If there is no impact on final output then we can use On Error Resume Next statement.

> When not to choose:

If there is any impact on final output then don't use.
------------------------------------------------
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"
-------------------------------------------------
On Error Resume Next
Dim a, b, c
a =100
b-200
c= a + b
Msgbox a+b
-----------------------------------------
Recovery Scenarios:
What is Recovery Scenario?
It is scenario, makes UFT from abnormal state to normal during execution.
------------------------------------------
Why Recovery Scenarios?
During Test execution UFT may face some problems, if we provide Recovery Scenarios then UFT recovers from abnormal state to normal and continues its execution.
------------------------------------------------------
Trigger Events:
a) Popup window

b) Test Run error

c) Object state

d) Application Crash
-----------------
Recovery Operations:
i) Keyboard or Mouse operation

ii) Close Application Process

iii) Function call

iv) Restart MS Windows

Create New Recovery Scenario

Associate Recovery scenarios (Internal/External) (Test Level/Tool Level)

Edit Recovery Scenario (If required)

Delete Recovery Scenario (If required)
--------------------------------------------
Recovery Scenario is file
.qrs
---------------------------
SystemUtil.Run "C:\Program Files\HP\Unified Functional Testing\samples\flight\app\flight4a.exe"
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set "asdf"
Dialog("Login").WinEdit("Password:").SetSecure "55306afc407d5012934700380b861c5e3392bc19"
Dialog("Login").WinButton("OK").Click

If Window("Flight Reservation").Exist(10) Then
    Window("Flight Reservation").Close
    Result = "Login Successful - Passed"
    Else
    If Dialog("Login").Dialog("Flight Reservations").Exist(3) Then
    Dialog("Login").Dialog("Flight Reservations").WinButton("OK").Click
    Dialog("Login").WinButton("Cancel").Click
    End If
    Result = "Login Successful - Failed"
End If
Msgbox Result
-------------------------------------------------------

0 comments:

Post a Comment