Configure the JMeter JSR223 Assertion assertions: properties, defaults, and practical usage notes for building reliable load tests.
Part of the Assertions category. Also documented in context in the full Component Reference.
The JSR223 Assertion allows JSR223 script code to be used to check the status of the previous sample.
| Name | Required | Description |
|---|---|---|
| Name | No | Descriptive name for this element that is shown in the tree. |
| Language | Yes | The JSR223 language to be used |
| Parameters | No | Parameters to pass to the script. The parameters are stored in the following variables: - Parameters - string containing the parameters as a single variable - args - String array containing parameters, split on white-space |
| Script file | No | A file containing the script to run, if a relative file path is used, then it will be relative to directory referenced by “user.dir” System property |
| Script compilation caching | No | Unique String across Test Plan that JMeter will use to cache result of Script compilation if language used supports [Compilable](https://docs.oracle.com/javase/8/docs/api/javax/script/Compilable.html) interface (Groovy is one of these, java, BeanShell and JavaScript are not) :::note See note in JSR223 Sampler Java System property if you’re using Groovy without checking this option ::: |
| Script | Yes (unless script file is provided) | The script to run. |
The following variables are set up for use by the script:
log- (Logger) - can be used to write to the log fileLabel- the String LabelFilename- the script file name (if any)Parameters- the parameters (as a String)args- the parameters as a String array (split on whitespace)ctx- (JMeterContext) - gives access to the contextvars- (JMeterVariables) - gives read/write access to variables:vars.get(key); vars.put(key,val); vars.putObject("OBJ1",new Object()); vars.getObject("OBJ2");props- (JMeterProperties - classjava.util.Properties) - e.g.props.get("START.HMS"); props.put("PROP1","1234");SampleResult,prev- (SampleResult) - gives access to the previous SampleResult (if any)sampler- (Sampler) - gives access to the current samplerOUT-System.out- e.g.OUT.println("message")AssertionResult- (AssertionResult) - the assertion result
The script can check various aspects of the SampleResult.
If an error is detected, the script should use AssertionResult.setFailureMessage("message") and AssertionResult.setFailure(true).
For further details of all the methods available on each of the above variables, please check the Javadoc