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

StackOverflow https://stackoverflow.com/questions/20843935

Question

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

Was it helpful?

Solution 2

Following some advice, here's how i did it:

The HTTP request has a Regular Expressions Extractor to extract the XPTO variable from the request. Then, a BeanShell PostProcessor saves data to a CSV file:

String xpto_str = vars.get("XPTO");
log.info("Variable is: " + xpto_str);

f = new FileOutputStream("/tmp/xptos.csv", true);
p = new PrintStream(f); 
this.interpreter.setOut(p); 
print(xpto_str + ",");
f.close();

Then, in second thread group, i added a CSV Data Set Config, in which i read the variable from the file. This is really easy, just read the guide (http://jmeter.apache.org/usermanual/component_reference.html#CSV_Data_Set_Config).

Thanks

OTHER TIPS

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top