Correlation is the method of capturing dynamic values which comes as a server response and sending the captured value to subsequent request. In this article on JMeter correlation, Iam mentioning about different types of extractors available in JMeter and how to use them in correlating dynamic values.

In JMeter, you can use extractors of different types to perform correlation. The extractor, as the name indicates, extracts the dynamic value and stores it in a variable if you need to pass the stored value in the next requests. Below mentioned are different types of extractors available in JMeter.

  • CSS Selector Extractor
  • JSON Extractor
  • Boundary Extractor
  • Regular Expression Extractor
  • XPath Extractor

How to add extractor?

Step1-Identify request wherein the extractor needs to be added.
Step2-Right click on the request select add, select Post processors, and click on the type of extractor whichever needs to be added.

when to do correlation?

Response for a request will have different values. For easiness let us categorize these values as static values and dynamic values. Since static value remains the same, you do not need to capture it using any extractor. Dynamic values change in every time. If a value is dynamic and it is coming in any subsequent request, you should correlate it.

Now let us go through the details on each extractor available in JMeter

Types of extractors

CSS Selector Extractor

You can plan to use CSS selectors or XPath extractors if you need to capture a dynamic value from an HTML or XML response. The CSS extractor in the example mentioned below extracts all headings of a webpage. Once you have tested the extraction using the CSS selector tester, apply the CSS selector extractor.

CSS Selector Tester
Extracting 5th heading content using CSS Selector Extractor.

JSON Extractor

You can use JSON extractors particularly when you need to capture a dynamic value from a JSON response. In the below example created data is a dynamic response value. As shown in the screenshot, we use a JSON path expression to capture the created value using JSON extractors.

Json Extractor Tester
Json extractor
Json path Tester
Validating Json path expression using json path tester before applying it

Boundary Extractor

We can capture the dynamic value using the boundary extractor by identifying its left and right boundary. In the below mentioned example id number is a dynamic value.
Now to capture this dynamic value we need to identify left and right boundaries and add it in respective fields as mentioned in screenshot.

Here in below mentioned example left boundary is {“id”:” and right boundary is “,”created At

{“id”:”132″,”createdAt”:”2023-04-27T08:37:48.790Z”}

Jmeter boundary extractor

Regular Expression Extractor

Dynamic value from a response can be extracted used using regular expression extractor. Here in this example dynamic id number is captured using regular expression “(.)” In this regular expression “.” indicates any character or integer value and “” indicates any numbers of values following the first value.

Jmeter regular expression extractor

XPath Extractor

XPath extractor becomes handy specially during other extractors like boundary and regular expressions extractors fails to capture the desired dynamic value from the response. It is useful in getting values from HTML tags similar to CSS extractors.

Xpath tester
XPath Extractor

Interested in learning more about Xpath ? , visit this website to learn more on Xpath Tutorial Point

checking extractor before applying

It is important to validate correlation before applying it. You can do it in either of the ways mentioned below.

1)Navigate to response for a particular request in “View Result Tree”. Apply the regular expression in search bar and select “Regular exp” option and click Find.

dynamic value response

2)Navigate to response for a particular request in “View Result Tree”. Select from the dropdown extractor tester of your choice. In this example it is boundary extractor tester. Place left and right boundary accordingly and click test. If you fill the input information appropriately, then only you will get the results.

Regular expression tester
Boundary extractor tester

Passing captured Correlated value to next request

To pass the captured or correlated value you need to pass the variable name as mentioned below (in screenshot). In the subsequent request to create user2, we use the ID value captured in the create user1 response. This is applicable to values captured using any JMeter extractors.

Format to keep the value in request is ${Variable Name}.

jmeter boundary extractor
Boundary extractor with a variable name as C_Id1
Replace correlation value to next request
The variable ${C_Id1} is used in the second request body create User2.
dynamic value captured from response.
ID having dynamic value 6 is captured in variable C_Id1
dynamic value passed in response.
Dynamic Id value “6” is sent in second request create User2

You may also like….

JMeter API Testing

JMeter API Testing

JMeter API Testing In this article on JMeter API testing, we will be discussing the details on...

read more

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *