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

문제

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

도움이 되었습니까?

해결책 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

다른 팁

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top