4
votes

I'm finding the way to use the variable sampler in JSR223 Sampler, JSR223 PreProcessor, JSR223 PostProcessor, and all other JSR223 script.

There are some other variables like vars, props, prev, SampleResult. I can use them easily.

For example:

  • vars: vars.get("VARIABLE_NAME"), vars.put("VARIABLE_NAME","VALUE"), ...
  • props: props.get, props.put, ...
  • prev: prev.getTime(), prev.isSuccessful(), prev.getLatency(), ...
  • SampleResult: SampleResult.getResponseCode(), SampleResult.getResponseMessage(), ...

But I don't know how to use variable sampler. Only thing I can do with this variable is:

sampler.sample(): It helps to returns the Name of current Sampler

So, could anyome please let me know there is any other way to use this variable?

Thanks in advance!

2

2 Answers

3
votes

sampler is a Sampler object. you can use whatever the methods available here, not only methods declared in Sampler class but also the methods in super classes/interfaces like TestElement.

For example:

sampler.sample() - returns sampler's name
sampler.setProperty() - set a property by specifying key, value
sampler.setThreadName() - set thread name for the sampler.
3
votes

For JSR223 Sampler sampler variable stands for JSR223Sampler, see the JavaDoc for all available methods and fields.

When it comes to JSR223 Pre or Post Processor - in that case sampler variable stands for parent sampler class instance, for instance in case of HTTP Request it will be HTTPSamplerProxy, for JDBC Request - it will be JDBCSampler and so on.

You can check exact class using Groovy expression like:

log.info(sampler.getClass().getName())

Groovy sampler variable

You can check How to Use BeanShell: JMeter's Favorite Built-in Component guide for more information on pre-defined variables and their usage. It is applicable for Groovy as well.