Correlation is very important concept of JMeter performance scripting. It is applied when you are required to fetch dynamic values from the response of earlier requests to supply to successive requests. If you are doing performance testing of a static website, just follow steps from my previous post on Performance Testing using JMeter. Simple record and run with multiple threads, no further customization is required. But, most of the web applications we deal contains dynamic content that is returned from web server.

A dynamic response always return with different data for each iterative request and may affect the subsequent requests. Correlation if implemented properly extracts the dynamic value from the response, store in a variable and use it in all required requests.┬áLet’s try to understand concept of Correlation using an example.

Correlation Example:

User can login into portal using valid credentials. For successful authentication, server generates a unique token to prevent system from CSRF(Cross Site Request Forgery) threat. It is the extra layer of security provided by CMS like Liferay. System authenticates user after validating this p_auth token value. Hence, for every sign-in request there must be a unique auth token. Web browsers automatically fetch and pass the token value but when performing same scenario using Jmeter, every thread must have a valid unique p_auth value. The solution for this scenario is Correlation.


Jmeter deals with Correlation using Regular Expression Extractor. First we need to identify the target request which goes to server and bring the response containing the keyword we want to extract. Regular expression extractor then shoot the valid pattern of Regular Expression on the response. Then it will store the extracted value in defined variable. Now, we need to find all requests containing the static value and replace with Reference Variable Name. To know more about Regular Expressions click this link.

How to Add Regular Expression Extractor:

First identify the request from which you want to fetch the value. Right Click on the Request > Add > Post Processors > Regular Expression Extractor.

Correlation

Now configure the extractor to fetch the dynamic value as shown in below image.

Liferay Performance Testing

Reference Name: This is the name of the JMeter variable to store the result.

Regular Expression: The expression to parse the data from response.

Template: The template is an arbitrary string with special elements. These elements refer to groups within the regular expression. The syntax ‘$1$’ refer to group 1, ‘$2$’ refer to group 2, etc.

Match No.: The regular expression may come up with multiple matches. You can tell extractor which one to pick. Value Zero indicates that JMeter can choose any random match.

Default Value: If Regular Expression does not match any value, then the reference variable will pick default value. You can keep “Fail” or “Incorrect Token Value” message as default value.

CLICK HERE FOR EXAMPLE OF REGULAR EXPRESSION EXTRACTOR IN JMETER.


Share This Article :