User Defined Variables! JMeter's tool to avoid duplication
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 www.tut.by as response. Next, parse received www.tut.by for some link and pass this link to the second request.
For extracting the link, I used Regular Expression Extractor.
The results of applying regular expression will be saved to variable second_url. Looking ahead, this will be link www.w3c.org
So, we’ve got the url from the response. And now we switch to the second 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.
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.
You might also find these useful:
Interested in writing for our Blog? Send us a pitch!