This sampler allows you to write a sampler using the \[http://www.beanshell.org/ BeanShell\] scripting language. |
Please note that the \[http://www.beanshell.org/ BeanShell\] jar file is not included with JMeter; it needs to be separately downloaded. For full details on using \[http://www.beanshell.org/ BeanShell\] please see the \[http://www.beanshell.org/ BeanShell web-site\]. |
Parameters
Attribute |
Description |
Required |
||
Name |
Descriptive name for this controller that is shown in the tree. |
No |
||
Parameters |
List of parameters to be passed to the script file or the script. |
No |
||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="718fce1b-3ea3-4800-a256-16b4b9b9734f"><ac:plain-text-body><![CDATA[ |
Script File |
Name of a file to be used as a [http://www.beanshell.org/ BeanShell] script |
Yes, unless Script filled in |
]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="153592fa-afba-4fba-a008-c388314efadf"><ac:plain-text-body><![CDATA[ |
Script |
Script to be passed to [http://www.beanshell.org/ BeanShell] |
Yes, unless Script File filled in |
]]></ac:plain-text-body></ac:structured-macro> |
N.B. Each Sampler instance has its own \[http://www.beanshell.org/ BeanShell\] interpeter, and Samplers are only called from a single thread. |
If the property "beanshell.sampler.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.
If a script file is supplied, that will be used, otherwise the script will be used.
Before invoking the script, some variables are set up in the \[http://www.beanshell.org/ BeanShell\] interpreter: |
The contents of the Parameters field is put into the variable "Parameters". The string is also split into separate tokens using a single space as the separator, and the resulting list is stored in the String array bsh.args.
The full list of variables that are set up is as follows:
When the script completes, control is returned to the Sampler, and it copies the contents of the following script variables into the corresponding variables in the SampleResult:
The Sampler ResponseData is set from the return value of the script.
The SampleResult variable gives the script full access to all the fields and methods in the SampleResult. For example, the script has access to the methods setStopThread(boolean) and setStopTest(boolean). Here is a simple (not very useful!) example script:
if (bsh.args[0].equalsIgnoreCase("StopThread")) {
log.info("Stop Thread detected!");
SampleResult.StopThread(bsh.args[1]);
}
return "Data from sample with Label "+Label; |