Error handling in UFT – Part 1

It is very common to get error while writing some program. But there should be a proper way to handle the errors, capture them and report them. Before jumping to error handling,let’s understand what type of errors UFT throwes. There are 2 types of errors.

1. Syntax error
2. Run time error

Syntax Error: These errors occur when there is some typos in the program like you didn’t close the bracket,there is a dot in variable name etc.UFT will show you these error in error pane at compile time or while saving the script. It will not let you proceed unless until you correct those errors.
You can also check that syntax of the program is correct or not by pressing ‘Ctrl+F7’.
Error

 

Run Time Errors: These are the errors which are evaluated during execution. It might occur due to the following reasons:

1. Trying to read the array index which is greater than size of array i.e. Array Index out of bounds.
2. Reading data from the file which is not available i.e. File not found.
3. Perform operation on the object which is not available i.e. Object not found
4. Perform incorrect arithmetic operation i.e. Dividing a number by Zero.

Handling run time errors:
There are several ways to handle the errors.

1. Handling with test settings: We can instruct UFT to take a predefined action when error occurs. We can access those settings by going to the path ‘File –> Settings–>Run(Tab)’.
You will see a dropdown ‘When error occurs during run session’. Choose a appropriate option as per the need.

Errorsettings

2. Using On Error Resume Next: 

  • On Error Resume Next – instructs UFT not to throw the error message box if any error occurs. Instead, It will move to the next line of code. It totally depends on the user’need, when he/she wants to bypass the errors.
  • On Error Go To 0 – will disable the error handling activated by On Error Resume Next.
3. Using Err object: This err object is in-built feature of Vbscript which will capture the error number and description of error. It will be helpful in debugging the code and can be useful for reporting as well.

  • Err.Number: Captures the Error number.
  • Err.Description: Captures the error description.
If at any point of time, we feel to stop the execution and exit the Test or Action. We have the following commands to do that.

ExitTest Exits from the entire Test. Nothing will run after this.
ExitAction Exits the current action.
ExitActionIteration Exits the current iteration of the action.
ExitTestIteration Exits the current iteration of the UFT test and moved to the next iteration.
Descriptive programming
Error handling in UFT - Part 2
Shekhar Sharma

Shekhar Sharma

Shekhar Sharma is founder of testingpool.com. He is an automation engineer having more than 8 years of experience who loves troubleshooting in automation and finding innovative ways to solve the problems. His other leisurely activities includes playing harmonica, paintings, sketching portrait, watching movies and travelling etc.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *