Professional Documents
Culture Documents
Error Handling in QTP
Error Handling in QTP
Error Handling in QTP
Within every Script we have to think about possible exceptions and how
to handle them. Especially in the uppermost layers of the script, it is
important to handle all exceptions.
QTP and VBScript give the Test Engineer some tools to handle errors and
Exceptions.
Error Preventing:
When an error occurred, Report it in detail. When working with GUI objects,
use the Window.Exist property. Every If…Then..End If statement has the Else
part, the same for
Select Case. Use Case Else.
a) Synchronization
b) Exist Property
c) Recover Scenarios
d) On Error Statement
www.gcreddy.com 1
QTP Training
Parts:
GoToline
Enables the error-handling routine that starts at the line specified in the
required line argument. The line argument is any line label or line number. If
a run-time error occurs, control branches to the specified line, making the
error handler active. The specified line must be in the same procedure as the
On Error statement, or a compile-time error will occur.
GoTo 0
GoTo -1
Resume Next
Specifies that when a run-time error occurs, control goes to the statement
immediately following the statement where the error occurred, and execution
continues from that point. Use this form rather than On Error GoTo when
accessing objects.
End Function
Call Sum(gcr,bannu)
www.gcreddy.com 2
QTP Training
e) Error Object
The Err object is an intrinsic object with global scope — there is no need to
create an instance of it in your code.
The properties of the Err object are set by the generator of an error — Visual
Basic, an Automation object, or the VBScript programmer.
When a run-time error occurs, the properties of the Err object are filled with
information that uniquely identifies the error and information that can be
used to handle it. To generate a run-time error in your code, use the Raise
method.
The Err object's properties are reset to zero or zero-length strings ("") after
an On Error Resume Next statement. The Clear method can be used to
explicitly reset Err.
Example:
Properties
Description Property
HelpContext Property
HelpFile Property
Number Property
Source Property
Methods
Clear Method
Raise Method
www.gcreddy.com 3