How to Handle Correlation in JMeter?

April 9, 2024
5 min read
Share this post

Generally, if you visit a website, you will come across 2 types of content- Static and Dynamic Content. Static content is one that is fixed and pre-written and that will not change as per the user request. For example, the Contact Us Page with the company address and contact details is a static page. Now, if we see Dynamic Content, as the name suggests, dynamic content is generated based on the user request. If we take the example of a shopping website, suppose we are searching for software testing books in the search bar. A list of software testing books are retrieved from the database and displayed to the user as per the user query. Now, this is what we call dynamic content. I hope all of you must have a basic understanding of what static content and dynamic content are.

Now, if I want to test how a web server will handle static content and dynamic content, the approach is very simple for the static content. I will simply record a test script and execute it with multiple threads, and that script will just run fine.

However, the majority of the websites that we see today are not that simple. They mostly have dynamic content, that JMeter needs to know how to capture that content and reuse it in subsequent requests. This is what correlation exactly means. Correlation is the process of capturing and storing the dynamic values from the web server and passing it on to subsequent requests.

In this blog post, our aim will be to discuss what is Correlation? Why do we need a Correlation? Is Manual Correlation the only option for the developers?

WHAT, WHY and WHERE?

Correlation is a very critical and crucial process during performance load testing. If it is not handled properly, the script will become useless.

Please Note: Correlation can only be ignored in case of static content.

Let's look at a few scenarios to give you a better understanding of when the correlation is required.

  1. When the specification is clearly for static text, no matter what other conditions are, there is definitely no need for correlation.
  2. If the test requires the creation of a post and involves the user in performing actions like posting a reply to comment. In this case, it is clearly a dynamic content, so we require correlation here.
  3. No correlation is required where there is a concept of cookies, as JMeter's HTTP Cookie Manager is capable of handling cookies.

Through these examples, we just want you to get an idea of the situations where correlation is required. All you need to look for dynamic content, and we are done with the decision.

Please Note JMeter doesn't have a native autocorrelation feature, so we have to perform correlation manually. You need to be more cautious while performing manual correlation, as you need to manually identify the correlation points in the test flow and maps the value to be replaced in consecutive requests.

How to do a Correlation?

Two basic steps are involved in performing correlation in JMeter:

  1. The first and foremost requirement will be to identify and extract the dynamic data from a key request and assign it to a variable. You can use Regular Expression Extractor. To add Regular Expression Extraction, Right Click on Test Plan → Add → PostProcessor → Regular Expression Extractor.
Regex extractor
  1. Finally, now we can reuse the variable defined in the above step in every subsequent occurrence.

Automatic Correlation?

If you have a small script, it is easy to determine the correlation points. But for a large script, determining correlation points is a very time consuming and error-prone task. For the large script, my advice would be to break it into small scripts and try to keep each individual small script atomic, which means they need to be as far as less dependent on each other.

However, this process consumes time, cost and also error-prone. So, it is advisable to automate the complete process of determining correlation points in test flow. There are many third-party tools out in the market that do this job of automating the task of identifying the correlation points in the test flow and then the generated JMX file can be imported and used in JMeter for further analysis.

Rupesh Garg
Rupesh Garg
CEO and Chief Architect
Our blog

Latest blog posts

Discover the latest in software testing: expert analysis, innovative strategies, and industry forecasts
Software Testing

Top 12 Software testing myths debunked

Rupesh Garg
Rupesh Garg
May 8, 2024
5 min read
Software Testing
Testing Tools

Exploring Software Testing with Selenium Framework

Rupesh Garg
Rupesh Garg
May 6, 2024
5 min read
Software Testing
Testing Tools

Exploring Software Testing with the Right CI/CD Toolset in 2024

Rupesh Garg
Rupesh Garg
May 6, 2024
5 min read