How to use err object to continue test execution in VBSript and QTP
''Err object holds the information for last runtime error that occurred in the test execution
'' In the piece of code, we can add on error resume next to continue with execution . It will not abort the execution but will store the information of the error.
'' Once a new runtime error occur, in that case , the err object stores the information of new error. So handle must be taken to add reporting in test and clearing the error
''Methods for err object are err.raise and err.clear
'' On error Resume next will continue with execution. try to comment the On error resume next , and then see what happens in case on error resume next statement is not provided.
On Error Resume Next
'' Err.raise <number> will generate err object for err number provided. At runtime as an error is encountered, err object populates the information of error.
Err.Raise 9err_number= Err.number
'' Using err.description, we can extract information about the error
err_description= Err.description
'' In case no error is encountered in the execution , the err. number has number as 0. Therefore we can use If else loop based on value of err.num and report to the QTP Report.
If numerr <> 0 Then
''Reporter.Reportevent ........
msgbox (numerr & " Some error in application")
Else
''Reporter.reportevent ........
End If
'' Once we have validated a piece of code, we should clear the err using err.clear
err.clear
msgbox err.number
''you will see msgbox will display value as 0 now.
No comments:
Post a Comment