Some actions added to the generated script code can succeed or fail during a test. The Generation Rules Wizard provides options on the Select Success/Failure options page for you to specify for what you want to happen in the event of a success or failure.
The following information about using success and failure options is provided below:
Rules That Use Success and Failure Options
You can specify success and failure options for three types of rules. Brief explanations of these types of rules follow:
Data Correlation Rules
When a virtual user (VU) tries to extract a value from a response from the server, the before or after text it searches for may or may not be found in the response (for example, if the server returns an error page). A data correlation rule correlates the associated values so that during a test the virtual users send back the value they received from the server and not what was received during the recording. For more information about using the Data Correlation rule, see Data Correlation Rule.
The Data List Correlation Rule works similarly for lists. See Data List Correlation Rule for more information about it.
The purpose of a verify rule is to check whether a response from the server is what was expected. The verification check may or may not succeed. All types of Verify rules can use the success and failure options: Verify Title, Verify HTTP Response Code, Verify Contains, and Verify Response Length.
Specify Actions to Take
To specify what actions to take in the event of success or failure for an action, perform the following steps:
Choose an Action to take on failure. The possible actions are:
- Raise an exception
- Immediately stop the VU
- Move the VU onto the final sequence of scripts
- Move the VU onto the next sequence of scripts
- Move the VU onto the next iteration
- Move the VU onto the next script
- Generate a warning message and continue
- Generate an error message and continue
- Do nothing
These actions are passed to the script method as a value from the
Optionally, specify Code to execute on success and Code to execute on failure. If you provide code in these fields, it is inserted into the generated script inside a simple
if ... elseblock. Use the Insert code snippet button to add prewritten code to the Code to execute on success field.
You can use four special macros in the Code to execute blocks of code, and the correct variable will be substituted for the macro when the script is generated. The context for these blocks of code is always the same: a
Request object has been created using a particular
Url object, and then
Request.send() has been called and the resulting response returned as a
Because these objects are stored in variables with different names depending on where they appear in the generated script, it is difficult to refer to them directly. Using the macros within the code blocks eliminates this difficulty:
$url- replaced with current
$request- replaced with current
$response- replaced with current
$index- replaced with the current request index (an integer literal).
You can use these macros anywhere you would normally use these variables, such as parameters to a method in your custom virtual user script. Notice the
$index macro in the Code to execute on success in the sample screen above.
If you need to provide more than a few lines of code in either of these boxes, then a better way might be to define a function inside your custom VU script source containing the success or failure code, and then put a call to that function in the box on this page.