Unexpected errors or events during test run
which interrupt test are called Exceptions.
Exception/Error
handling ways:
VB script error handling
o
Using Test Settings
o
Using On Error Statement
o
Using Err Object Properties
o
Using Exit Statement
·
Recovery Scenarios
Test settings: Error
handling
Exception/Error handling can be defined in
Test Settings through FileàSettingsàRun as shown below,
On Error Statement:
Error handling
On error statement is used to handle the
errors by the tester rather than allowing VB Script engine to display error
messages.
On Error Resume Next:
Causes the execution to continue with next
line of code when error is occurred.
On Error GoTo 0:
Disable
error handling if you have previously enabled error handling using On Error
Resume Next.
Err Object: Error
Handling:
Err
object contains information about run-time errors.
Err
object is built in object with global scope.
Properties:
Number: Number is the default property of the
Err Object and it contains numeric value specifying error.
If
the value of Err. Number is 0, no
error has occurred.
Description: Description property
returns or sets a descriptive string associated with an error.
When
the run-time error occurs, the properties of Err object are filled with
information that uniquely identifies the error and information that can be used
to handle it.
Methods:
Raise: To
generate a run-time error in your code, use the Raise method.
Clear: The Clear method clears all
property settings of the Err object.
Using
Exit Statement: Error Handling
Exit Statement can be used
in conjunction with err object to exit from a test/action/iteration in case of
an error encountered. Following are the exit statements that can be used
in QTP to exit from a particular state:
ExitTest: Exits the
entire QTP test or Quality Center business process test, regardless
of the run-time iteration settings.
ExitAction: Exits the current
action.
ExitActionIteration: Exits the current
iteration of the action.
ExitTestIteration: Exits the
current iteration of the QTP test or Quality Center business process test and
proceeds to the next iteration.