Correlation

                    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 expression
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-
(left boundary) (body to be capture) (right boundary)
For example : The server is returning the session id for login request . we wanna capture that session id .For that we have to use regexpression extractor
server returning value is
session id =”1e234323254343464”/>?
Left boundary = session id=”
body to capture = 1e234323254343464
right boundary = ”/>?
The regurar expression is ---------- session id =”(.+?)” />?
If we use the above expression every reply the expression will extyract the server return value.
Where
. “- match any character
“+” - one or more times
“? “- stop when first match succeeds
Steps to follow to capture dynamic value:
step 1: open jmeter
step 2: Add thread group
step 3: add sampler
step 4: Add regular expression extractor
From the following screen shot you can find more details.
Configeration elements in regular expression:
Name : you can give any meaning ful name as a name.
Name of created value : give any meaning full name but to use extracted / dynamic value some where at that time we have to use same name as a parameter.
Regular expression: here we have to peaste the regular expression which is formed by you.
Templet: here enter the posion of occurence of the dynamic value (ex : if it is first occurance then give like $1$)
Match no : If you wanna pick random number then give 0 if not leave blank.




No comments:

Post a Comment