Wednesday 6 August 2014

Jmeter Correlation

Correlation is one of the important enhancements that need to be changed in the script. Correlation talks about handling the dynamic data in the script, which is generated by server.

When you record your script for the first time, all such dynamic values are captured & recorded in the script. Moreover, when you replay such script directly, without doing correlation, you may get session invalid message etc.

Session expire message is due incorrect (expired) session id is passed along with request. Session id (or any other dynamic value) is recorded at the time recording and same value, which is actually expired, is sent next time when you reply the script. 


 How to identify dynamic values in a script?

 1. When you re-run the script, the script gets failed with some error.











2. Review the script and check the input parameters sent via request. This is called identification of dynamic value.



 






3. Now we need to correlate the dynamic values sent by the server like device id and offline date in this example.The reason script fails, is the values are unique for each user and cannot be re-used, Jmeter re sends the same ids again in the request and hence it fails.


Steps for Correlation :

1. Identification of dynamic values. 











2. Add “Regular Expression Extractor” post processor of JMeter in the request.


Right Click on the HTTP request which has the dynamic value, and ADD--> PostProcessor --> Regular Expression Extractor.

 





3. Replace the dynamic value with the regular expression in the HTML TAG and add in Regular expression.


RegularExpression: BV_SessionID="(.+?)"
Template :Enter $1$
Match No. : Enter 1


4. Replace the dynamic value with the variable name on all locations where the same dynamic value appears. Use ${var_name} format to replace. 







5. Now run the script again and see the results in View Result Tree. Check the values in Database, if the actual request has been created.


 

No comments:

Post a Comment