Sunday, 11 October 2015

Regular Expression Extractor

What is correlation and why it is required?

Correlation is the most important aspect of scripting. It generally 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 and 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.

Regular Expression Extractor-

Coming back to JMeter, consider an example where we have two operations-
1. User launch website
2. User fill details and click on OK button
Now, the call user launch website creates a dynamic variable event validation 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 call related to "User fill details and click on OK button" as Http post parameter.
Steps for correlating the Event validation values-

1. Run the script containing the both the above stated operations
2. Go to Response tab (Text mode) in "View Result Tree" listener of "User launch website" operation. BTW, we see the second operation "User fill details and click on OK button" in red because it is not yet correlated.



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



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 hardcoded value of Event Validation variable.




7. Run the Test plan again.



J J J

No comments:

Post a Comment