Jul. 21st, 2016

Advanced Load Testing Scenarios with JMeter: Part 1 - Correlations

Dynamic data is data that is changed when information is updated. For example, session variables connected to authentication mechanisms. This affects website recording, as JMeter needs to know how to capture this dynamic data and reuse it in subsequent requests. Otherwise, playing back the recording will show many errors.

 

This is where Correlations come in. Correlations is the fetching of dynamic data from preceding requests and posting it to subsequent requests.

 

How does it work?

 

Record the test and export it to JMeter through the jmx button.

 

As mentioned, dynamic values change for each subsequent page request. Here we are looking at the Token value from a flight travel agency demo (if you follow us you know this is the same demo we use all the time). If the same Token is used, the script will fail.

 

HTTP Request

 

Add the View Results Tree Listener to see every request and response in detail.

 

Run the script.

 

The script has indeed failed because of the Token:

 

View Results Tree Listener

 

To correlate the value that is captured from the first page, we want to go back and find the value when it’s issued by the server.

 

In this example, you can find the hidden input in the form:

 

Hidden Input

 

This variable needs to be captured in the script for reuse as a variable for the rest of the script.

 

Copy the variable name and check it in the Regular Expression Tester and make sure you have the name right:

 

RegExp Tester

 

To turn the name into an expression that can handle dynamic data, se parentheses and matching operators. Test to make sure it works:

 

Dynamic Data expression

 

 

Go to the page where you found the value. Add a Regular Expression Extractor as a Post Processor.

 

Regular Expression Extractor Post Processor

 

Fill out the fields:

● Reference Name - What you choose to call the variable when referencing in the script.
● Regular Expression - The expression
● Template - How to name the variable. If we had multiple matches we could use a template that included each of them.
● Match - Which match we should use. 0 is any of the matches that could happen.
● Default Value - The output when the variable isn’t found.

 

Regular Expression Extractor


Now, we need to find the value in the subsequents samplers in each of the pages.

 

Replace the name with the value you found. Do the same for each value on each page:

 

Subsequent samplers

 

We also need to add a debug sampler to the script. The debug sampler shows the variables found as used in the script. If there is a problem with finding the match or verifying we found it right - it shows us that.

 

Debug sampler

 

Now, replay the script. Don’t forget to clear out and change back to ‘text’.

 

View Results Tree

 

Hurray! The errors are gone now and the samplers are successful, because the value was found. Notice it is a new value:

 

Token Value

 

Also shown in the debugger:

 

Debug sampler

 

Congratulations! You now know how to use correlations. For automated scripting, check out BlazeMeter’s ‘SmartJMX’ feature. SmartJMX automatically correlates every variable, by finding the source of every URL, GET parameter, POST parameter, or JSON POST field. When finding a candidate, SmartJMX attaches the variable extractor to the corresponding sampler and uses the extracted variable instead of the constant value.

 

Learn more about advanced load testing on JMeter from our free Webinar.

 

Stay tuned for part 2 - Data-driven testing and assertions on JMeter

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