HP QTP Utility Statements : SetLastError Statement
September 10, 2018
HP QTP Utility Statements : SetLastError Statement
Welcome to this post! – ” HP QTP Utility Statements : SetLastError Statement”.
If you are looking for HP UFT, QTP utility statements and their usages, then you are at right place. This post “HP QTP Utility Statements : SetLastError Statement” consists of concept discussion and usage discussion. Go ahead and enjoy reading…
This discussion will help you prepare well if you are going for the interview and can help you if you need the function to be used in your project test suite.
SetLastError Statement
Abstract
The SetLastError statement is used to set the latest error found in the execution or the run. The statement in itself falls under the category of utility statements and not utility objects. Remember there is a difference between utility statements and utility objects.
Before we dig down deep into the usage let’s quickly visit some general questions.
In the interview usually, you might be questioned in different ways like:
- How to set error during the test run?
- Can you associate the SetLastError statement value to DescribeResult statement?
- What are the objects and parameters of SetLastError statement?
- is SetLastError is an object or statement?
- How can you show the description of last error occurred in the execution?
Discussion
When you create the test using some framework like hybrid, keyword driven or data driven, there is always a possibility of running into error. There are various errors which occur in the execution these can be math related, object related, system related etc. Whatever the case be if you want to proceed to next step by capturing the old error for later references then you can set via statement SetLastError .
Usually tester use the on error goto statement to return the code status to 0. But it’s a good practice to keep the error description in the log so that later you can analyze the log for pass and failures.
Hence, officially the main purpose of the SetLastError statement is to insert a VBScript error into the test script. All the error code relating to Microsoft Windows Script can be found at Microsoft site.
Syntax
SetLastError(Number)
Let’s see the parameters and their usage description for this statement:
Argument | Type | Description |
Error | Integer | The error. |
Example
In the following example, the script fails to run successfully because the Password Image was not found on the Mercury Tours page and uses the SetLastError function to place the “Out of memory” error into the test script
The error code of the error can be retrieved using the GetLastError statement, and then the DescribeResult statement displays the text description of the error code in a message box.
'SetLastError example Browser("Mercury Tours").Page("Mercury Tours").Image("Password").Click 21, -11 SetLastError(7) msgbox(DescribeResult(x))
This brings us to the end of our discussion on “HP QTP Utility Statements : SetLastError Statement”.
I really hope you have enjoyed reading this short post. If you have any doubt on this please feel free to add your comment below.
And if you like to read more on UFT or QTP Technical Interview Questions please follow below links:
UFT Technical Interview Questions – Set 1
UFT Technical Interview Questions – Set 2
How to Download Resource From QC\ALM?
How to Upload Resource To QC\ALM?
Or if you prefer General Interview Questions please follow below links:
UFT General Interview Questions – Part 1
UFT General Interview Questions – Part 2
If you would like to keep track of further articles on UFT (QTP). I recommend you to SUBSCRIBE by Email and have new UFT articles sent directly to your inbox.