Become a JMeter and Continuous Testing Pro

Start Learning

Test Your Website Performance NOW!

arrow Please enter a URL with http(s)

JMeter's User Defined Variables Helps to Avoid Code Duplication

User Defined Variables! JMeter's tool to avoid duplication

User Defined Variables

How do we use use variables in one thread group?

You can store values that can be used in different parts of the load testing scenario.

Great, but what to do if you need to pass some values from one HTTP request to another? 

Answer? The same: user-defined-variables, but in another way.

We created a simple test-plan containing 2 requests. The first request receives page as response. Next, parse received for some link and pass this link to the second request.

View Results Tree

For extracting the link, I used Regular Expression Extractor.

Regular Expression Extractor
The results of applying regular expression will be saved to variable second_url.  Looking ahead, this will be link
So, we’ve got the url from the response. And now we switch to the second request.

Second URL HTTP Request
Here we'll use the second url.
The test plan is now ready for execution (off with their head!!! kidding...kidding).

You see link that will be used as a URL in the 2nd request.

Let’s see what was executed.

We see that the variable second_url was passed to the second request without using any configuration elements.

Here is a lil' riddle for you. Will this method work if we place the second request to another Thread Group?

Let’s test it.

Thread Group
What will we have in View Results Tree?

Nothing! The variable name was not changed with its value, because, unfortunately or fortunately (I don’t know for sure), the variable cannot be passed between different Thread Groups in JMeter. But you are lucky because we know how to do it. Look for the answer in an upcoming blog post.

arrow Please enter a URL with http(s)

You might also find these useful:

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