Correlation is the most important aspect of scripting. It usually includes fetching dynamic data from preceding requests/calls and posting 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-
->User enters login details and click OK button
->Home page opens and user take further actions
Now, if we just playback this script, the test will fail even for a single user. This is because of the authentication mechanism used. 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. So, one cannot just record and playback the requests having these variables. Here, we need to correlate the web requests with the dynamic variables. And for correlation, we need to use the "Regular Expression Extractor" which makes use of regular expressions. So, before going deep into Correlation, let's first understand "Regular Expressions".
Regular expressions are used to fetch data from a string based on a search pattern. Basically, in order to extract any value (generally a dynamically created value) from a string response, we define a left bound of the variable then some wildcard characters and then a right bound-
E.g. if we have text response like-...__EVENTVALIDATION"value="weriudflsdfspdfusdjhsdihffgdfgpdfjsdjfpj" />...
And we need to extract the value of Event validation variable using regular expressions; the regular expression for the same will be-
If you do not want to get deeper into regular expressions, then the wildcard characters (.+?) would suffice in most of the cases. For more information on regular expressions and meaning of each wild card character visit Regular-Expression info Website.
Coming back to JMeter, consider an example where we have two operations-
Now, the call "User launch website" creates a dynamic variable - 'eventVvalidation' that we can check in Response Data tab of "View Result Tree" listener for the call. The value of this variable is then passed to subsequent calls related to "User fill details and click on OK button" as Http post parameter.
Steps for correlating the Event validation values-
3. Create a Regular expression for extracting the value of Event validation variable's value. As stated above the R.E. for this will be-
__EVENTVALIDATION" value="(.+?)" />
4. Go to http request under "User Launch Website" transaction controller-> Add -> Post Processor -> Regular Expression Extractor.Adding "Regular Expression Extractor" control
5. The reference name inserted is the name of the variable created that will capture the Event validation value generated by the http request under "User launch website" operation.
6. Now pass this variable to the subsequent http request under "User fill details and click on OK button" as post request- overriding the already present hard-coded value of Event Validation variable.Request without correlation (Hardcoded values)
7. Run the Test plan again. All green! That's it.
This was all about correlation. In order to get good understanding of correlation (or scripting for that matter) we need to have a good understanding of two things- the knowledge of the dynamic variables generated by the programming languages/platform and Regular expressions. Thanks for reading!!