Over a million developers have joined DZone.

Here’s What to Do to Combine Multiple JMeter Variables

This quick tip will walk you through building a JMeter Variable from two or more other variables.

Evolve your approach to Application Performance Monitoring by adopting five best practices that are outlined and explored in this e-book, brought to you in partnership with BMC.

Periodically when implementing advanced JMeter test scenarios, you may need to build a JMeter Variable from two or more other variables. This short post will look at how to do just that.

These test scenarios might originate from a Counter Test Element or Function, the __threadNum()function, a regular expression resulting in multiple matches or perhaps a different need.

Let’s imagine the following situation:

There are 2 JMeter Variables:

  1. myVar_1 with the value of foo
  2. myVar_2 with the value of bar

There is also a Counter test element with the reference name of counter.

The objective is to have a dynamic combined variable which consists of:

  • Prefix: myVar_
  • Postfix: ${counter} variable value that is dynamic

The solution is using the __V() function which can be used to evaluate composite variables.

The syntax is:

${__V(PREFIX${POSTFIX})}

In the case above, the resulting composite variable reference would be:

${__V(myVar_${counter})}

See how to do this in the image below.

Combining JMeter Variables


One More Hint

If you build a data-driven test and have parameters in a file that you’re reading by using the__StringFromFile() or __FileToString() functions, and the file has JMeter Variables which need to be substituted with the corresponding values in runtime - you need to use the __eval() function so that the variable value could be resolved.

use the __eval() function in JMeter

Looking for More Info on JMeter Functions?

For more information on the above and other useful JMeter Functions check out the following articles:

Related Refcard:

Learn tips and best practices for optimizing your capacity management strategy with the Market Guide for Capacity Management, brought to you in partnership with BMC.

Topics:
jmeter ,monitoring ,performance

Published at DZone with permission of Dmitri Tikhanski, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}