nrjsingh167
nrjsingh167

Reputation: 11

How to store variable in property in jmeter using beanshell post processor and refrence that variable in next request.

I am hitting an http url and need url contents into property in jmeter. I have done the fetching part from url,but unable to store the value in properties using the jmeter.

For e.g. Request is like http://url/user=admin,password=admin

I need property in jmeters

property1(user)=admin property(password)=admin

Upvotes: 1

Views: 9515

Answers (1)

Dmitri T
Dmitri T

Reputation: 168197

Given you have already extracted what you need it might be easier to use __setProperty() function like:

${__setProperty(foo,bar,)}

creates "foo" property with the value of "bar"


If you still want to go the "Beanshell" way, you can use props shorthand which provides read-write access to JMeter Properties (in fact it's instance of java.util.Properties) for properties manipulation.

The Beanshell script:

props.put("foo", "bar");

will create a property "foo" having value of "bar".

Returning to your use case, if your URL looks like http://example.com/?user=admin&password=admin use the following Beanshell code:

Map parameters = ctx.getCurrentSampler().getArguments().getArgumentsAsMap();

String user = parameters.get("user");
String password = parameters.get("password");

props.put("user", user);
props.put("password", password);

should do what you need. See How to Use BeanShell: JMeter's Favorite Built-in Component guide for more information on Beanshell scripting in JMeter.

Upvotes: 4

Related Questions