Thursday, January 17, 2013

Error handling in QTP (Using Codes)

On error Statements

Following are error statements :
1. On Error Resume Next
2. On Error Go to 0
3. err Object

4. Reporter.RunStatus
5.Reporter.ReportNote

1.On Error Resume Next:
On Error Resume Next statement enables the Error handling in the code.If there is error in the code "On error Resume Next" ignores it and continue with next line of code.

2.On Error Go to 0:
On error got to 0 statement disables error handling we have previiously enabled it by using On Error resume Next.

3.err.number and err.description:
Provides the error number and the description of the error

Err Object  has following methods :=
 a) Err.Raise
    ex: Err.Raise 6

b)Err.Clear

c)Err.Number

 lines of code which would raise the error :-
If err.number <> 0 ' which means that some error has occurred
msgbox err.description

your code logic if no error occurs :-on error goto 0 ' this stops your error handling code

Extract Error No:
msgbox Err.number

Example :
If Err.Number <>0 then
     msgbox("Here it prints") 'Because of Err object we can give our own error message
end if

Example:
On Error Resume Next
Err.Raise 8    'raise a user-defined error
Err.Description = "My Error"
Err.Source = "MyAppName"

4.Reporter.RunStatus
example (1) :
If Reporter.RunStatus=micFail then ExitAction

example(2):
If Reporter.RunStatus = 0 then ExitAction

0 or micPass: If this step runs test passes which is shown in test report.
1 or micFail: If this step runs test fails which is shown in test report.
2 or micDone: Used to send message to the test report and does not affect status of test.
3 or micWarning: Again, used to send warning message to the test report and does not affect status of test.

5.Reporter.ReportNote
Reporter.ReportNote ("Testing App Now")
Reporter.ReportNote ("The Results paths of Test Scripts") & vbtab &MyResultsPath

 

No comments:

Post a Comment