Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Advanced Load Testing Scenarios with JMeter - Part 1: Correlations

DZone's Guide to

Advanced Load Testing Scenarios with JMeter - Part 1: Correlations

Carrying forward dynamic data is an important part of load testing. Read on to find out how to use correlations in JMeter to assist with this.

· Performance Zone
Free Resource

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.

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 subsequent 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.

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

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:
data ,requests ,regular expression ,results ,dynamic ,jmeter ,load testing ,quality assurance

Published at DZone with permission of Noga Cohen, 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 }}