· Application Type:
· Project Type:
Target readers: Performance Testers
Keywords: Correlation, Performance
Introduction
While creating vuser script some data of object will be taken in to the script and few data values has to be generated by the application during time. User can not exit or pass any parameter to it. So we can write some programs which takes this value and output some other values again we pass it to other function like …show more content…
that we can get final output as the value which can be at the time of running the application.
This document quotes the main two types of correlations and the different methods to capture them in Load Runner. This document will prove very helpful to any newbie to Load Runner.
Example from a real practice:
A Load Runner script for a web server was recorded, which contained two special fields - timestamp and checksum:
web_submit_data("rms.jsp", "Action=http://www.google.com/", "Method=POST", "RecContentType=text/html", "Referer=http://eprumossd0010:8400/RMS/html/testFramework.html", "Snapshot=t4.inf", "Mode=HTML", ITEMDATA, "Name=TIMESTAMP", "Value=1192177661211", ENDITEM, "Name=CHECKSUM", "Value=715E19300D670ED77773BBF066DAAAE2866484B8", LAST);
The scheme of this interaction is the following is depicted in the following diagram:
[pic]
Every time a client web browser connects to web server, server gets current time stamp, calculates checksum and sends them to client. These two fields are used to identify a current session. In other words, the pair of timestamp + checksum is analog of session ID.
Where is the problem? Let's replay the recorded LR script.
The problem occurs when I try to execute my recorded script.
Web server checks its current time with a time stamp, sent by client. If client's data is out-of-date or incorrect, then server returns an error:
The parameter "CHECKSUM" is not found or has invalid value.
There is the scheme for this interaction:
[pic]
Client cannot re-use old (i.e. hard-coded) values for times tamp and checksum. It must request new data.
So, instead of hard-coded values, LR script should process dynamic data, returned from server. This can be done using a correlation:
[pic]
The definition of correlation is: ✓ Correlation is the capturing of dynamic values passed from the server to the client.
Correlation can be done with 2 ways: 1. Automatically 2. Manually
Automatic correlations in most cases do not work correctly. Manual correlation is an accurate method though.
The algorithm of manual correlation is the following: 1. Find a dynamic value to capture. 2. Find server's response, containing the dynamic value. 3. Capture the dynamic value. Special parameter will be used instead of dynamic value. 4. Replace every occurrence of dynamic value in script with the parameter. 5. Check changes.
Now, l will describe each step in details: 1. Find a dynamic value to capture Always try to record and save two equal VuGen scripts. After that, open menu item "Tools / Compare with Scripts..." and you can compare both recorded scripts in WDiff: [pic]
2. The differences are highlighted by yellow. This highlighting means that lines (parameters values) change from run to run. So, most probably, these values should be correlated.
Tips: Sometimes, comparing of two scripts cannot detect dynamic values. Imagine, that you recorded this script: "Name=SessionID", "Value=A38E9002A41", ENDITEM, "Name=CurrentMonthID", "Value=4", ENDITEM, ... It's obvious, that SessionID should be correlated. What about CurrentMonthID parameter? Second recorded script can contain "Value=4" too. And it's possible, that your script will work correctly during the April (4th month is April), and will not work from 1st May!
3. Tips: Look through the source code of recorded script. Timestamp, CheckSum, SessionID, and different IDs - all of they are potential candidates to be correlated.
Tips: Most importantly, check out for warnings in the re-play logs. These may cause the script to work incorrectly though the script passes.
Tips: Execute your script with enabled run-time viewer (menu "Tools / General Options.. / Display"). Any shown errors ("Page not found", "Session timeout", etc) indicate about potential correlations.
4. Find server's response, containing the dynamic value Before script executing, please enable extended logging from "Vuser / Run-Time Settings...": [pic]
5. Then execute script. Open Replay (Execution) log and find server's response, which contains dynamic values of TIMESTAMP and CHECKSUM: [pic]
6. In the response, we can see where server sends both dynamic values. And we can find the step that returns these values. This is 13th line - Action.c (13). Double click the line, containing timestamp’s and checksum's values, 13th line of script will be opened: web_submit_data("generateChecksum.jsp", "Action=http://eprumossd0010:8400/RMS/jsp/generateChecksum.jsp", "Method=POST", "RecContentType=text/html", ... This means that server's response for generateChecksum.jsp page contains dynamic values which should be correlated.
7. Capture the dynamic value There are two ways how to capture a dynamic value: o Automatic capturing from Tree-view o Manual from Script-view These ways are similar enough. Also, they use the same function - web_reg_save_param.
We can start from: o Automatic capturing from Tree-view. Open Tree view (menu "View / Tree view"): [pic] o Then: ▪ click "View recording snapshot only" btn (2); ▪ select generateChecksum.jsp page from tree view (3); ▪ select "Body" to view body of server's response (4).
As result, you will see recorded values of CHECKSUM and TIMESTAMP (5).
Now, select value of first dynamic value (checksum), right-click, and select "Create parameter": [pic]
After that you will see the message box: [pic]
You can create parameter for dynamic value. If you want to replace all occurrences of dynamic value ("715E19...") in script, press "Yes" btn. To not replace all occurrences, press "No" btn.
Tips: It is recommend to not replace all occurrences of dynamic value. It can lead to incorrect results. It's more preferable to replace occurrences one by one with "Search and Replace" dlg.
OK, I click "No" btn.
Return to Script-view ("View / Script View") and see changes. There are new lines, inserted before generateChecksum.jsp page:
// [WCSPARAM WCSParam_Text1 40 715E19300D670ED77773BBF066DAAAE2866484B8] Parameter {WCSParam_Text1} created by Correlation Studio web_reg_save_param("WCSParam_Text1", "LB=window.parent.setChecksum("", "RB="", "Ord=1", "RelFrameId=1", "Search=Body", "IgnoreRedirections=Yes", LAST);
web_reg_save_param function finds and saves a text string from the next server's response. In other words, it captures a dynamic value.
In this example, web_reg_save_param function will save the captured value into WCSParam_Text1 parameter. The function finds the left boundary (window.parent.setChecksum(") and after that it finds the right boundary ("). The string, found between left and right boundaries, will be saved to WCSParam_Text1 parameter. Ord attribute indicates the ordinal position of captured value. In the example (Ord=1), we capture the value between first left boundary and left one. Easy to guess, that "Search=Body" means search in a body of server's response.
Note: the capturing of TIMESTAMP parameter is similar. It generates the following code:
// [WCSPARAM WCSParam_Text2 13 1192177661211] Parameter {WCSParam_Text2} created by Correlation Studio web_reg_save_param("WCSParam_Text2", "LB=, ", "RB=)", "Ord=1", "RelFrameId=1", "Search=Body", "IgnoreRedirections=Yes", LAST);
o Manual capturing from Script-view. Actually, this method consists in a manual writing of web_reg_save_param function. It requires strong knowledge on this function and its parameters.
8. Replace every occurrence of dynamic value in script with the parameter
Open "Search and Replace" dlg ("Edit / Replace..."). And replace one-by-one hard-coded values with a parameter.
Why it is important? Imagine, that we have the following code:
web_submit_data("somepage", ... "Name=OrderNumber", "Value=125", ENDITEM, "Name=UserID", "Value=125",
If we create parameter for UserID, and perform replacing of all occurrences of its value ("125"), then it will produce the code:
web_submit_data("somepage", ... "Name=OrderNumber", "Value={WCSParam_Text1}", ENDITEM, "Name=UserID", "Value={WCSParam_Text1}",
It may be wrong! OrderNumber can be static value and be equal to 125, while UserID may change.
9. Check changes After above manipulations, our script will look like:
web_submit_data("rms.jsp", "Action=http://eprumossd0010:8400/RMS/jsp/rms.jsp", "Method=POST", "RecContentType=text/html", "Referer=http://eprumossd0010:8400/RMS/html/testFramework.html", "Snapshot=t4.inf", "Mode=HTML", ITEMDATA, "Name=TIMESTAMP", "Value={WCSParam_Text2}", ENDITEM, "Name=CHECKSUM", "Value={WCSParam_Text1}", ENDITEM, // others parameters ... LAST);
The statement "{WCSParam_Text1}" means "get value of WCSParam_Text1 parameter". So, current algorithm is: o when server returns different values of CheckSum and TimeStamp o then web_submit_data captures and places them into WCSParam_Text1 and WCSParam_Text2 parameters o after that we use {WCSParam_Text1} and {WCSParam_Text2} get current values of parameters and use them in scripts
Tips: To get/debug a captured value of parameter, use the following statements: lr_output_message("Value of WCSParam_Text1: %s", lr_eval_string("{WCSParam_Text1}")); lr_output_message("Value of WCSParam_Text2: %s", lr_eval_string("{WCSParam_Text2}"));
LoadRunner Correlation - How to capture an array of dynamic data with web_reg_save_param function
Imagine, that server returns the following response:
[pic]
And we have to capture dynamic values of all IDs (underlined with green lines). These values can be used later - say, for LoadRunner script correlation.
As usual, several solutions exist let’s see them:
1.
Insert five web_reg_save_param functions using "Ord=1" (2, 3, ...) attribute:
1. web_reg_save_param ("ID1Value", "LB= value="", "RB="", "Ord=1", LAST); 2. web_reg_save_param ("ID2Value", "LB= value="", "RB="", "Ord=2", LAST); 3. web_reg_save_param ("ID3Value", "LB= value="", "RB="", "Ord=3", LAST); 4. web_reg_save_param ("ID4Value", "LB= value="", "RB="", "Ord=4", LAST); 5. web_reg_save_param ("ID5Value", "LB= value="", "RB="", "Ord=5", LAST);
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.
[pic] OK, let's execute our script and see results - whether values will be captured or not: [pic]
As you can see, web_reg_save_param functions executed correctly and parameters contain values.
Just to clarify, we used "Ord" attribute. It indicates the ordinal position or instance of the match. Read LoadRunner Help on web_reg_save_param function for detailed …show more content…
info.
Another solution is to not use "Ord" attribute.
Instead of it, we will extend boundaries to capture values from a server response.
2. Insert five web_reg_save_param functions with extended boundaries:
1. web_reg_save_param ("ID1Value", "LB=ID1" value="", "RB="", LAST); 2. web_reg_save_param ("ID2Value", "LB=ID2" value="", "RB="", LAST); 3. web_reg_save_param ("ID3Value", "LB=ID3" value="", "RB="", LAST); 4. web_reg_save_param ("ID4Value", "LB=ID4" value="", "RB="",
LAST); 5. web_reg_save_param ("ID5Value", "LB=ID5" value="", "RB="", LAST);
I extended left boundaries and included ID1, ID2, etc with inverted quote. Since new boundaries will define values explicitly, we don't need use "Ord" attribute. That's why I deleted "Ord" attribute from web_reg_save_param function.
Let's execute new code and see results: [pic]
Now is a time to introduce third way how to capture an array of dynamic data. For that, we will use "Ord=All" attribute of web_reg_save_param function:
3. Insert web_reg_save_param function using "Ord=All" attribute:
1. web_reg_save_param ("IDValues", "LB= value="", "RB="", "Ord=All", LAST);
Let's execute it and see results: [pic]
Values captured. There are several important items here: 1. We specified one web_reg_save_param function only with "Ord=All" attribute, and it captured all values. 2. 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. 3. Additional parameter was created automatically - "IDValues_count". It contains number of matches saved to the parameter array.
Please, see this example - how the usage of "_count" LoadRunner parameter to iterate all items in a array of captured values:
1. web_reg_save_param ("IDValues", "LB= value="", "RB="", "Ord=All", LAST); 2. 3. // get number of matches 4. nCount = atoi(lr_eval_string("{IDValue_count}")); 5. 6. for (i = 1; i