Correlation in JMETER
This post
is related JMeter. We will discuss correlation process/ method in Jmeter.
As I mentioned
before, JMeter does not support automatic correlation. We use regular
expression to performing correlation in JMeter.
Now let’s
move to Correlation in JMETER.
What is correlation.
To capture
a dynamic value from server response in performance testing is Correlation.
It fetches dynamic values from earlier
responses and supplies those values to subsequent requests.
Why we need correlation?
Most of
the time, web application which has time based, user-based concept implemented,
Server sends dynamic response basis of various factors like unique username
password, OTP, time/date.
A dynamic response always returns 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
Regular Expression Extractor
This is
feature which used for correlation in JMETER. We can add "Regular Expression Extractor" using post processor section as below image
Let me
explain each field name of this window
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.
Apply To: This field indicate samplers that can generate
sub-samples, e.g. HTTP Sampler or samples generated by the Transaction
Controller.
-Main sample and sub-samples: Apply to
Main & Subsample both
-Main sample only: Only applies to the main sample
-Sub-samples only: Only applies to the
sub-samples
-JMeter Variable: Assertion is to be
applied to the contents of the named variable
Field to check: this says which part of response values should
be searched using regex.
-Body: body of the response, e.g. the content of a
web-page (excluding headers)
-Body (unescaped): body of the response,
with all Html escape codes replaced. Note that Html escapes are processed
without regard to context, so some incorrect substitutions may be made.
-Body as Document: extract e text from various type of documents
via Apache Tika
-Response headers: Header of response in
HTML pages
-Request headers: to look into request
headers of html page
-URL: As name suggest, URL of Response
-Response code: As we know each response
has standard code e.g. 200
-Response Message: like O.K. message in Response
Note: Body(unescaped) and Body as Document
can impact performances so, use wisely
Now see
steps we should follow to do correlation using above template:
1. Run
the test and try to identify the dynamic value in the in the View Results Tree.
Note:
Need to
run for multiple times and compare the results manually.
2.Identify the LB, RB of the dynamic value
3. Write the regular expression for the
dynamic value using the LB and RB. Check the regular expression using View Results Tree.
4. Find
the occurrence (match number) for the required dynamic value
5. Add
the regular expression extractor for the previous request.
Hopefully
this post will give a picture on correlation process of Jmeter.
Happy
Testing!!
To start
with JMeter and Regular expression, you can go through my previous post on JMeter
and Regex
Comments
Post a Comment