2020 / JANUARY / 27

Corelation JmeterRegular Expression Extractor

How to Handle Correlation in Jmeter

How to Handle Correlation in Jmeter

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, Contact Us Page with 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 we call dynamic content. I hope all of you must have a basic understanding of what static content and dynamic content is.

Now, if I want to test how a web server will handle static content and dynamic content, Approach is very simple for the static content. I will simply record a test script and execute it with multiple threads and that script would 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?


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 cookie, 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 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.


Recommended Posts