Correlation

Correlation
Correlation is the mechanism of capturing the dynamic value and replacing it in the script during replay.


Why to do correlation
 If you try to replay a script without correlating, the script is most likely to fail. Server will not reply to the requests it sends. In most of the cases, the session ID will be invalid when the script is run without correlation, so the server will not allow you into the site. It will throw errors and shows abnormal behavior.  Please have a look at the pictorial diagram for more clarity.










































Which value needs to be correlated?
Any value which changes dynamically every time needs to be correlated.


What errors are thrown when correlation is not done?
There are no specific errors that are associated with correlation, but there are errors that could occur because a value has not been correlated.  For example, if an invalid Session ID is sent to a Web server, how that server responds depends on the implementation of that server.  It might send a page specifically stating the Session ID is invalid and ask you to log in again.  It might send an HTTP 404 Page not found error because the requesting user did not have permissions for the specified page, and so the server could not find the page.
In general, any error message returned from the server after the script makes a request that complains about permissions can point to a hard-coded value that needs to be correlated


How to find out the values to be correlated?
Please follow below steps to find out values which are changing dynamically and need to be correlated
                -Record 2 scripts for a scenario, use the same test data
                -Compare the 2 scripts using Windiff tool (utility)


Types of correlation
There are below methods of correlation.
1)      Manual Correlation
2)      Auto correlation              
a.       Scan for correlation
b.      Correlation rules

Manual Correlation
Manual correlation can be done using different ways, 3 most common methods are mentioned below

Manual correlation using replay log
-          Follow the above defined procedure to find out if there are any values to be correlated.
-          Replay the script with extended log’s “Data returned by server” option checked in run time settings
-          Find the dynamic value (do not find the dynamic value which is in the script but search for its prefix) in replay log, ignore the value and move to the next occurrence if it is not in response body.
-          Find the left and right boundary.
-          Create web_reg_save_param() function.
-          Double click on the value in Replay log, cursor will be highlighting a function in the script above which Web_reg_save_param () has to be placed.
-          Replace all the occurrences of that particular dynamic value in the script.
Manual correlation using Generation log
-          Follow the above defined procedure to find out if there are any values to be correlated.
-          Replay the script with extended log’s “Data returned by server” option checked in run time settings
-          Find the dynamic value (actual dynamic value, not the field name) in generation log, ignore the value and move to the next occurrence if it is not in response body.
-          Find the left and right boundary.
-          Create web_reg_save_param() function.
-          Keep the cursor on the dynamic value and search for .inf in upward direction. Some function will be shown. Above that function place your correlation function Web_reg_save_param () in the script.
-          Replace all the occurrences of that particular dynamic value in the script.
-          Select the dynamic value and replace it with parameter.

Scan for correlation
Please follow below procedure to scan for correlation.

-Replay the script
-Click on scan for correlation as shown below





-All dynamic values which need to be correlated will be highlighted. Select each one and click   on “Correlate” button. Please look at below picture for more clarity.









Correlation rules
There are some set of pre-defined correlation rules for few applications which can be used for correlation. However you can define your correlation rules and use them for your own application. You can go to Recording options - > Correlation , you will see the below window where you can create new application rules.






























Correlation rules can be imported and exported. Extension of correlation rules file is .cor.

What is ordinal?

ORD: Indicates the ordinal position or instance of the match. The default instance is 1. If you specify "All," it saves the parameter values in an array. This attribute is optional.
ORD=1:
web_reg_save_param ("ID1Value", "LB= value=\"", "RB=\"", "Ord=1", LAST);

ORD=2:
 web_reg_save_param ("ID2Value", "LB= value=\"", "RB=\"", "Ord=2", LAST);

ORD=ALL
web_reg_save_param ("IDValues", "LB= value=\"", "RB=\"", "Ord=All", LAST);

There are several important items and we would like to pay your attention:
·         We specified one web_reg_save_param function only with "Ord=All" attribute, and it captured all values.
·         Captured values were saved into parameters with automatically generated names.
Please, note that I specified initial parameter name - "IDValues". Values were saved into parameters "IDValues_1", "IDValues_2", "IDValues_3", etc. So, an array of values were created.
·         Additional parameter was created automatically - "IDValues_count". It contains number of matches saved to the parameter array.
How to get count for captured values from response?
count = atoi(lr_eval_string("{var1_count}"));
lr_output_message("%d",count);
How to use all values from array?           
for(i=1; i<=count;i++)
                {
                                sprintf(str, "{var1_%d}", i);
                                lr_save_string(lr_eval_string(str),"var2");
                                lr_output_message(lr_eval_string("{var2}"));
                }
How to use any random value from array?
lr_save_string(lr_paramarr_random("var1"),"var2");

Pass var2 as variable in future required requests. Like below example.



Note:
Please, note that web_reg_save_param function does not perform correlation. web_reg_save_param function just registers a request for correlation from the next server response. That's why web_reg_save_param function should be placed before action functions, such as: web_url, web_submit_form, and others.

Comments

Popular posts from this blog

Loadrunner Functions

Analyzer in LoadRunner Part1

Analyzer in LoadRunner Part 2