Jmeter: How to create an array in bean shell post processor and make it available in other thread groups?

luistm picture luistm · Dec 30, 2013 · Viewed 10k times · Source

Does anyone knows how to create an array in bean shell post processor and make it available in other thread groups?

I've been searching for a while and i'm not managing to solve this.

Thanks

Answer

Dmitri T picture Dmitri T · Jan 4, 2014

There is no need to do it through writing and reading files. Beanshell extension mechanism is smart enough to handle it without interim 3rd party entities.

Short answer: bsh.shared namespace

Long answer:

assuming following Test Plan Structure:

Thread Group 1 
    Beanshell Sampler 1
Thread Group 2
    Beahshell Sampler 2

Put following Beanshell code to Beanshell Sampler 1

Map map = new HashMap();
map.put("somekey","somevalue");
bsh.shared.my_cool_map = map;

And the following to Beanshell Sampler 2

Map map = bsh.shared.my_cool_map;
log.info(map.get("somekey"));

Run it and look into jmeter.log file. You should see something like

2014/01/04 10:32:09 INFO  - jmeter.util.BeanShellTestElement: somevalue

Voila.

References:

  1. Sharing variables (from JMeter Best Practices)
  2. How to use BeanShell: JMeter's favorite built-in component guide