Dynamic response in software testing provides different values for different iterations. This might affect the subsequent requests. This JMeter Correlation article will show you how to store the dynamic value from the response, store in a variable and use it in all required requests in the following sequence:
What is Correlation?
Correlation is the process of extracting some value from the response of one step into the request of another step. It captures and stores the dynamic response from the server and passes it on to subsequent requests. So, What is a Dynamic Response?
A response is considered dynamic when it returns different data for each iterating request, occasionally affecting successive requests. Correlation is a crucial process during performance load test scripting because if we don’t handle it carefully, the script will become useless.
Why do we Need Correlation?
Correlation is one of the most important aspects of scripting. It fetches dynamic data from preceding requests and posts it to the subsequent requests. Let’s take an example to find out why exactly we need correlation. Suppose we have recorded a scenario in which:
- A user enters login details and clicks OK button
- Home page opens and the user takes further actions
When we login to a website, session variables are dynamically created. These session variables are passed to the subsequent requests and help validation & authentication of the actions performed. Here, we need to correlate the web requests with the dynamic variables otherwise the test will fail. And for correlation, we need to use the Regular Expression Extractor.
So, let’s see how to use Regular Expression Extractor in JMeter before we get into the details of Correlation.
Steps to Use Regular Expression Extractor
There are 4 steps that you need to follow while using Regular Expression Extractor in JMeter. It includes:
- Creating a Test Plan in JMeter
- Adding Regular Expression Extractor in the Test Plan
- Refer the extracted value in the next step
- Run and Validate the Test
Now let’s move ahead and see how to use this extractor in JMeter Correlation with an example.
JMeter Correlation: Demo
The first thing you need to do is download and install the JMeter tool in your system. If you have any doubts regarding this tool, you can check out the JMeter Tutorial and How to Install JMeter for more knowledge.
Steps to Achieve Correlation in JMeter
- Firstly, you have to start your JMeter and select the Test Plan.
- Next, Right click on the Test Plan and add a Thread Group.
- Then you have to add HTTP Request and enter the Server name or IP of any Website. This will be the Request for Step 1. Right click on Thread Group, select Sampler and add HTTP Request.
- After adding the Server Name in HTTP Request, you need to add the Regular Expression Extractor to extract some value from the Response of Step 1. Right Click on HTTP Request, select Post Processors and add Regular Expression Extractor.
- Once you have added the Regular Expression Extractor, there are four important fields that you need to fill for successful extraction of some response value.
1. Name of Created Variable – Specify any variable name
2. RegularExpression – Add any Regular Expression that you want to obtain from the server
3. Template – Add the number of Groups in your Regular Expression
4. Match No. – Add any number of matches for your Regular Expression
- Now, we need another HTTP Request whose request data will be extracted from the response data of the first HTTP Request.
1. Right Click on the Thread Group and add another HTTP Request.
2. In the second step, you need not specify any Server Name. Take the reference of the Variable Name and set it as a Path for your second HTTP Request.
3. The name should be specified with ‘$‘ and curly braces.
- To view the Test Result and see the correlation between the two steps, you need to add a Listener. Right Click on the Thread Group, select Listener and add View Results Tree.
- The final step is to Run and Validate the Test. Once the test is successful, you will see that some Response value of the first HTTP Request is extracted as the Request for the second HTTP Request. This shows the Correlation between the two steps.
These are the steps that will help you achieve Correlation in JMeter with the help of Regular Expression Extractor. I hope you understood the different steps involved in the process.
Now that you know how to achieve Correlation in JMeter, check out the Performance Testing Using JMeter Course by Edureka. This course provides you insights into software behavior during workload. In this course, you will learn how to check the response time and latency of software and test if a software package is efficient for scaling. It will help you check the strength and analyze the overall performance of an application under different load types.
Got a question for us? Please mention it in the comments section of “JMeter Correlation” and we will get back to you.