Loadrunner : How to pass a correct correlation value to the request when the ordinal value and total count of correlated parameter is inconsistent?

Step 1: Token is the Correlation parameter which needs to be captured properly.

Step 2: Since the Total count of the Correlation parameter is inconsistent, we will capture all the values using "Ordinal=ALL",

web_reg_save_param_ex(
"ParamName=Token",
"LB=\"token\":\"",
"RB=\",\"theme\"",
"Ordinal=ALL",
SEARCH_FILTERS,
"Scope=Body",
"RequestUrl=*/user*",
LAST);

web_url("ui", XXXXX, LAST);

Step 3: Save the total count of the correlated parameter to the variable tokencount.

tokencount = atoi(lr_eval_string("{Token_count}"));

Step 4: Pass each value one by one to the request using a for loop.

for (i=1; i <= tokencount; i++)

{

sprintf(crttoken, "{Token_%d}", (i));
lr_message(crttoken);

Step 5: Now I am passing the correlation value to the header. Similarly it can also be passed to the body of the request.

web_add_auto_header("__token__",
lr_eval_string(crttoken));

Step 6 : Check if the passed correlation parameter retrieves proper response using the web_reg_find function. (Here I am doing a negative check.)

web_reg_find("Text=You have Signed Off",
        "SaveCount=Count",
        LAST );

web_custom_request("getData", XXXX, LAST);

Step 7: Validate the text count, if the condition is true repeat the loop else break the loop.

if (atoi(lr_eval_string("{Count}")) > 0){

        lr_output_message( "Improper response retrived. Repeating the loop");
       
        }
       else{

         lr_output_message( "Proper response retrived. Exiting the loop" );
break;

}

}

Article by Vinoth Srinivasan

Loadrunner Function lr_save_var to convert C variable into loadrunner parameter

Loadrunner
lr_save_var:

This loadrunner function saves the defined bytes of a content from a one variable to the other.

Syntax:

lr_save_var(source parameter, value length(bytes), option, destination parameter)

C Program:

In our below C program we are going to see how the file content stored in a c variable is converted to a loadrunner parameter. (comments highlighted in RED matters)

//#include <stdio.h>
#define SEEK_SET 0 /* beginning of file. */
#define SEEK_CUR 1 /* current position. */
#define SEEK_END 2   /* end of file */


Action()
{
 long infile; // file pointer
 char *buffer; // buffer to read file contents into
 char *filename = "test.txt"; // file to read
 int fileLen; // file size
 int bytesRead; // bytes read from file
 //
 // open the file
 infile = fopen(filename, "rb");
 if (!infile) {
    lr_error_message("Unable to open file %s", filename);
    return;
 }


 // get the file length
 fseek(infile, 0, SEEK_END);
 fileLen=ftell(infile);
 fseek(infile, 0, SEEK_SET);
 lr_log_message("File length is: %9d bytes.", fileLen);


 // Allocate memory for buffer to read file
 buffer=(char *)malloc(fileLen+1);
 if (!buffer) {
    lr_error_message("Could not malloc %10d bytes", fileLen+1);
    fclose(infile);
    return;
 }


 // Read file contents into buffer & saves the file length in bytes to bytesRead 
 bytesRead = fread(buffer, 1, fileLen, infile);
 if (bytesRead != fileLen)
 {
    lr_error_message("File length is %10d bytes but only read %10d bytes", fileLen, bytesRead);
 }
 else
 {
    lr_log_message("Successfully read %9d bytes from file: ", bytesRead);
 }
 fclose(infile);


 // Save the C variable 'buffer' to a loadrunner parameter 'fileDataParameter'
 lr_save_var( buffer, bytesRead, 0, "fileDataParameter");
 free(buffer);
 lr_log_message("File contents: %s", lr_eval_string("{fileDataParameter}"));
}


In the above code

Source parameter -- File contents are stored in the c variable buffer.
Value length -- File length in bytes is saved in the c variable bytesRead.
Option -- By default set option to 0.
Destination Parameter -- File contents to be copied to the Loadrunner Parameter fileDataParameter.

While not done loop in Loadrunner


Loadrunner
Below is the scenario in which a request will be executed based on the while not done loop.

Code:

//While not done loop
while(!flag)
{

//Text check

web_reg_find("Search=Body", "SaveCount=PendingCounter", "Text=Pending", LAST);


//Request to be executed

web_url("IZ7_N2M81BG0K87C60AQE01L2O00M1=CZ6_N2M81BG0K87C60AQE01L2O0062=MEjavax.servlet.include.path_info!QCP_rlvid.jsp=_rvip!QCPBBDMyReportsView.jsp=_rap!ReportListBean.refresh=com.ibm.faces.portlet.mode!view==",
"URL=https://XXXXXX/wps/myportal/BBD/Home/bbdRptUserActivity/!ut/p/z1/{R6_1}/dz/d5/{L2_1}/p0/IZ7_N2M81BG0K87C60AQE01L2O00M1=CZ6_N2M81BG0K87C60AQE01L2O0062=MEjavax.servlet.include.path_info!QCP_rlvid.jsp=_rvip!QCPBBDMyReportsView.jsp=_rap!ReportListBean.refresh=com.ibm.faces.portlet.mode!view==/",
"Resource=0",
"RecContentType=text/html",
"Referer=https://XXXXXX/wps/myportal/BBD/Home/bbdRptUserActivity/!ut/p/z1/{R3_1}/",
"Snapshot=t121.inf",
"Mode=HTTP",
LAST);


//IF Block - condition

if(atoi(lr_eval_string("{PendingCounter}")) > 0)
{
flag = 0;

}
else
flag = 1;
}

Code Explained:

1. In the web_reg_find we are searching for the text 'Pending' and saving the text count in the variable 'PendingCounter'.

2. We are extracting the value from 'PendingCounter' using lr_eval_string and converting the string into integer using atoi function and passing the value as input to the IF Block.

3. If the text check is positive, IF Block will have value greater than 0 and the statement flag = 0 will be executed.
So the while condition becomes while(!0) == while(1) which is true and the request will be executed.

4.  If the text check is negative, IF Block will have value less than 0 and the statement flag = 1 will be executed.
So the while condition becomes while(!1) == while(0) which is false and the request will not be executed.



How to create Date & Time parameter in Jmeter

Sometimes we will have to create unique parameters, for which we can append the date and time value to our parameter names.

Creating Date & Time parameter in Jmeter.

In Jmeter we have __time function to create Date & Time parameters. This function has the below list of arguments that can be passed on to generate Date & Time in different formats. 

FunctionExample Result for
01/12/2018 02:00PM
${__time(YMD)}20181201
${__time(yyyyMMdd)}20181201
${__time(yyMMdd)}181201
${__time(dd-MM-yyyy)}01-12-2018
${__time(dd/MM/yyyy hh:mm:ss)}01/12/2018 14:00:00
${__time(dd/MM/yyyy HH:mm:ss a)}01/12/2018 02:00:00 PM
${__time()}1454358328739
${__time(yyyy-MM-dd’T’hh:mm:ssX)}2018-12-01T14:00:00+13
In the below image (Fig 1) email id is parameterized with date & time parameter. It can be seen that _time function is appended to the name mani (highlighted) thus the email id becomes mani${_time(YMD)}@ex.in

Fig 1
Once it is executed we can see that the date and time parameter is passed in the Response data in Fig 2. We can pass any of the above listed arguments to the _time function.

Fig 2


How to do correlation when the boundaries are dynamically changing?

Loadrunner
Consider a scenario when the Left and Right Boundaries are dynamically changing, using which we will have to capture the correlation value.

1. If the LB and RB has dynamically changing numbers:

Then your LB and RB becomes LB/DIG & RB/DIG and replace the dynamically changing numbers in the boundary with #.

Example:

Iteration 1: City001"Chennai"001City
Iteration 2: City002"Bangalore"002City
Iteration 3: City003"Delhi"003City

Here we can see that LB and RB are getting incremented from 001 to 003. So, our boundary becomes

LB/DIG = City00#\"
RB/DIG = \"00#City

2. If the LB and RB has dynamically changing alphanumeric values:

Then your LB and RB becomes LB/ALNUM & RB/ALNUM and replace the dynamically changing alphanumeric values in the boundary with ^.

Example:

Iteration 1: Citya01"Chennai"a01City
Iteration 2: Cityb02"Bangalore"b02City
Iteration 3: Cityc03"Delhi"c03City

Here we can see that LB and RB are getting incremented from a01 to c03. So, our boundary becomes

LB/ALNUM = City^^^\"
RB/ALNUM = \"^^^City



SaveOffset attribute in web_reg_save_param

Loadrunner
SaveOffstet:

SaveOffset attribute defines how many places after the Left Boundary, dynamic value should be captured.

Example:

radiobutton1="Chennai"

Dynamic value to be captured is Chennai

web_reg_save_param("City",
"LB=radiobutton",
"RB=\"",
"SaveOffset=3",
LAST);

Result:

City = Chennai

Here, the LB is radiobutton and we have mentioned the SaveOffset as 3 . So it will capture Chennai leaving 1=" (3 places after the LB) and save it in the Correlation Parameter City.

Standard deviation and its importance in performance testing

What is Standard Deviation?

Mathematical Definition : It is the measure of how spread out the numbers are around the mean.
Performance Definition : It is the measure of how response time is spread out around the mean.

It is denoted by Sigma (σ).


Formula: 

square root of [ (1/N) times Sigma i=1 to N of (xi - mu)^2 ]

Where

N = Count of the response time
x = Individual response time value
μ = Mean or Average response time

Importance of Standard Deviation in Performance Testing

  • Standard Deviation tells whether a transaction is consistent throughout the test or not.
  • A small standard deviation means that the response time of all the iterations of the same transaction are close to each other. 
  • So smaller the value more close the transaction response times are and more consistent the transaction is.
Example:


Lets calculate the Std. Deviation for the above transactions.

Login Transaction:

Step 1 - Average Response Time or Mean value =  5
Step 2
(5-5)²  = 0
(5-5)²  = 0
(6-5)²  = 1
(5-5)²  = 0
(4-5)²  = 1
Step 3 - (0+0+1+0+1)/5 = 0.4
Step 4  -  0.4 = 0.632

Inference :
In the Login transaction we can observe that response time of each iteration are close enough so the Std. Deviation is small. It means Login transaction is more consistent throughout the test.

Logout Transaction:

Step 1 - Average Response Time or Mean value =  5
Step 2 - 
(5-5)²  = 0
(4-5)²  = 1
(12-5)²  = 49
(3-5)²  = 4
(1-5)²  = 16
Step 3 - (0+1+49+4+16)/5 = 14
Step 4  -  14 = 3.741

Inference :

In the Logout transaction we can observe that response time of each iteration are having large deviations so the Std. Deviation is high. It means Logout transaction is less consistent throughout the test.