Become a JMeter and Continuous Testing Pro

Start Learning

Test Your Website Performance NOW! |

arrowPlease enter a URL with http(s)
Jun 10 2012

Knit One Pearl Two: How to Use Variables in Different Thread Groups

Our previous and most delightful post described how to use variables in a single thread group. But as you already know, it is impossible to pass variables between different thread groups.

How do we use variables when there is more than one thread group in a test plan? 

In the figure below we have a test plan containing two Thread Groups.

Thread Group
Before executing the test plan do not forget to set check-box “Run Thread Groups consecutively”. It is a must for executing Thread Groups one by one.
Test Plan
Let’s go to Regular Expression Extractor.
Regex Extractor
Result of Regular Expression will be stored in variable second_url.  And now shuffle on over to BeanShell Assertion.

BeanShell Assertion

Note the interesting construction: ${__setProperty(second_url,${second_url})}.

  • __setProperty() – is a built-in JMeter function that sets the value of a JMeter property. (A detailed description can be found here).
  • second_url – name of the property that will be set.
  • ${second_url} - is the variable that was stored in Regular Expression Extractor.

This is the line that is responsible for transferring the value between threads. From hereon out, the value of ${second_url}  can be accessed from any other thread group.

How can we increase the value? Look to the second request in Second Thread Group.
 Second Thread Group

To increase the property value, we use another JMeter function: __property().

It takes only one argument and the name of the property returns its value. A detailed description can be found here.

Got it? Good. Now let's execute the scenario!
 second_url property value was set as Server Name
Note that the second_url property value was set as Server Name. Great!

Knit one, pearl two. Bibbedy bobbedy boo.

Want to learn even more about JMeter, Performance and Load Testing?

Enter into our world of blazin' knowledge!

Are you a JMeter Guru looking for a flock?

Join our blazin' team

arrowPlease enter a URL with http(s)

You might also find these useful:

Interested in writing for our Blog?Send us a pitch!