Yavor
Yavor

Reputation: 11

In Jmeter, how do you store variables dynamically during runtime and use them later?

So I couldn't find an answer to this yet.

In JMeter:

I have 2 controllers, 1 loop and 1 while controller.

In the loop I create several objects. The system I create objects in gives them each an ID.

I want to store these IDs and reuse them later in the while controller and iterate through them all to perform an action on them.

I don't want to save to file, because I find that messy. I would like to store them in variables using beanshell.

Who can help me with this challenge? :)

Upvotes: 1

Views: 1423

Answers (2)

Yavor
Yavor

Reputation: 11

So basically, I did json path extraction in my loop controller and then store them in an arraylist using beanshell.

Then I used a forEach controller to iterate through that list.

It's messy but the best option available!

Upvotes: 0

Dmitri T
Dmitri T

Reputation: 168197

All Beanshell test elements come with vars shorthand which stands for JMeterVariables class instance.

  1. To store the variable: vars.put("variable_name", "variable_value");
  2. To read the variable: vars.get("variable_name");

Beanshell Variables Demo

See How to Use BeanShell: JMeter's Favorite Built-in Component to learn more about using JMeter and Java APIs in from Beanshell test elements.

Upvotes: 1

Related Questions