June 10, 2019

What Are JMeter Variables? How to Use Them

Open Source Automation

Do you know how to pass JMeter variables between different thread groups? Is it even possible? Find out!

In this blog, we break down the basics of JMeter variables in relation to thread groups. 

Table of Contents:

What Are JMeter Variables?

JMeter variables are local to a thread. You can access JMeter variables by going into thread groups. 

How to Use JMeter Variables With Multiple Thread Groups

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.

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!

Server name

Note that the second_url property value was set as Server Name. Great!

Go Beyond JMeter Variables With BlazeMeter

Go beyond JMeter variables and start testing with BlazeMeter today.



This blog was originally published on June 10, 2012 and has since been updated for accuracy and relevance.

Related Resources