JMeter __BeanShell function reference: syntax, parameters, and practical examples for parameterizing test plans with dynamic values.
Also documented in context in the full Functions and Variables reference.
The BeanShell function evaluates the script passed to it, and returns the result.
For full details on using BeanShell, please see the BeanShell web-site at http://www.beanshell.org/
A single instance of a function may be called from multiple threads.
However the function execute() method is synchronised.
If the property โbeanshell.function.initโ is defined, it is passed to the Interpreter
as the name of a sourced file. This can be used to define common methods and variables. There is a
sample init file in the bin directory: BeanShellFunction.bshrc.
The following variables are set before the script is executed:
log- the Logger for the BeanShell function (*)ctx- JMeterContext objectvars- JMeterVariables objectprops- JMeterProperties (classjava.util.Properties) objectthreadName- the threadName (String)Sampler- the current Sampler, if anySampleResult- the current SampleResult, if any
(*) means that this is set before the init file, if any, is processed. Other variables vary from invocation to invocation.
| Name | Required | Description |
|---|---|---|
| BeanShell script | Yes | A beanshell script (not a file name) |
| Name of variable | No | A reference name for reusing the value computed by this function. |
Example:
\$\{__BeanShell(123*456)\}
: returns 56088
\$\{__BeanShell(source("function.bsh"))\}
: processes the script in function.bsh