1
votes

Is it possible in jmeter to use the same variables in different BeanShell Sampler? My target is import my Amazon Kinesis Java application (converted ) into Jmeter, but part of this code is the connection and I want to set-up this once at the start-up of jmeter application. So I must re-use AmazonKinesisClient variable in different beanshell. Is it possible? thanks

PS: I have the same problem with JSONObject but in such case I have used a jmeter variable (storing json as String)

2

2 Answers

0
votes

You can use bsh.shared namespace as per Sharing Variables chapter of JMeter Best Practices guide.

In the first sampler:

JSONObject myObject = new JSONObject();
....
bsh.shared.myObject = myObject;

In the second (or whatever) sampler:

JSONObject myObject = bsh.shared.myObject;

For more Beanshell tips and tricks refer to How to use BeanShell: JMeter's favorite built-in component guide.

0
votes

If Both beanshell samplers are in the same thread, beanshell vars are shared between them.

vars.putObject("name",objectRef);
vars.getObject(“name”);