BeanShell Sampler (Beta Code)

This sampler allows you to write a sampler using the BeanShell scripting language.

Please note that the BeanShell jar file is not included with JMeter; it needs to be separately downloaded. For full details on using BeanShell please see the BeanShell web-site.






Descriptive name for this controller that is shown in the tree.



List of parameters to be passed to the script file or the script.


Script File

Name of a file to be used as a BeanShell script

Yes, unless Script filled in


Script to be passed to BeanShell

Yes, unless Script File filled in

N.B. Each Sampler instance has its own 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: BeanShellSampler.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 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:

With the following code you can access the HttpRequest body and modify it:

UserManual/Reference/BeanShellSampler (last edited 2010-06-03 14:07:02 by 93-62-154-5)