Tag Archives: loadrunner

Date Format Conversion in Vugen


char *date=”27 mar 2010″;
char *position;
int offset;
char *search_str[20] = {“jan”,”feb”,”mar”,”apr”,”may”,”jun”};
char *search_strvalue[20] = {“01″,”02″,”03″,”04″,”05″,”06″};
char * tokens;
char reqValue[100];
int i,j;

vuser_init()
{
lr_save_string(lr_eval_string(date),”date_new”);
lr_output_message(“%s”,lr_eval_string(“New date is {date_new}”));

j=0;
do
{
position = (char *)strstr(date, search_str[j]);
offset = (int)(position – date + 1);
j++;
} while (offset != 4);

tokens=(char *)strtok(lr_eval_string(“{date_new}”),” “);
i=0;
while (tokens!=NULL)
{
if(strcmp(tokens,search_str[j-1])==0)
{
strcat(reqValue, ” “);
strcat(reqValue, search_strvalue[j-1]);
strcat(reqValue, ” “);
}
else
{
strcat(reqValue,tokens);
}
tokens = (char *)strtok(NULL,” “);
}
lr_save_string(lr_eval_string(reqValue), “NewFormatDate”);

return 0;
}

Folder Creation Code in Loadrunner


Put this code inside the action:-

char filename[1024], command[1024];
char new_dir[] = “C:\\Sample”;

/* Create a directory under root called xyz and make it the current dir */
if (mkdir(new_dir))
lr_output_message(“Create directory %s failed”, new_dir);
else
lr_output_message(“Created new directory %s”, new_dir);

sprintf (filename, “%s\\%s”, new_dir, “SIVA.txt”);

/* Execute a dir /b command and direct it to a new file */
sprintf (command, “dir /b c:\\ > %s /w”, filename );
system(command);
lr_output_message(“Created new file %s”, filename);

return 0;

Send Email using SMTP protocol from Load Runner / Performance Center / StormRunner Load


Below is the snippet to be used for performance testing the SMTP server with bulk email messages or per your project needs,

 

Action()
{
// connect to smtp mail server
smtp_logon(“Logon”,
“URL=smtp://{P_userID}@mail.o365am.xxx.com:xxxx”,
“CommonName=SMTP {P_userID}”,
“LogonUser={P_LoginEmailID}”,
lr_decrypt(“5d564d6e185f6c5457b32fc024bc4a91aaacc3c”),
“STARTTLS=STARTTLS”,
LAST );

// send email
smtp_send_mail(“SendMail”,
“To={P_RecepientEmail}”,
“Cc={P_RecepientEmail}”,
“Bcc={P_RecepientEmail}”,
“From={P_LoginEmailID}”,
“Subject=Testing SMTP message from Load Runner”,
“ContentType=text/plain;”,
“charset=UTF-8”,
//     MAILOPTIONS,
//     “X-Priority: 3”,
//     “X-MSMail-Priority: Normal”,
//     “X-Mailer: Microsoft Outlook Express 5.00.2919.6700”,
//     “X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700”,
MAILDATA,
“MessageText=This is a simple mail from LR\r\n”,
LAST );

// wait time
lr_think_time(2);

// disconnect from server
smtp_logout();

return 0;
}

Communication Issue in AJAX True Client protocol


Issue: “communication between vugen and the truclient browser could not be established”. This error occurs when we click the ‘Develop Script’ button.

Solution: Simple step, Run the Vugen.exe as ‘Administrator’.

Activating the scripting mode in SAP


Inorder to start scripting the SAP applications using the Loadrunner tool, we have to enable the scripting mode available in the SAP application apart from the normal script enabling setting.

Please use the TCode – RZ11

Navigate to the page it allows and change the settings to ‘FALSE’ for the below mentioned parameters.

a. sapgui/user_scripting_set_readonly and set the value as “FALSE”
b. sapgui/user_scripting_force_notification and set the value as “FALSE”

TY

Using unique values (in Loadrunner scripts) using a prompt manner


In Loadrunner script, we use block size per vuser for using the huge range of unique values in a parameter. But during the test, if the execution failes inbetween its very hard to re-allocate the block size again by checking the unused values. In-order to solve this issue, we can use the LR_ADVANCE_PARAM function in loadrunner. Please find below the usage format to implement this.

 
Action()
{
int x,y,v,i;  // declare these variables as integer
v=atoi(lr_eval_string(“{VuserID}”));  // get the VuserID and store it in v
i=atoi(lr_eval_string(“{ItNum}”));  // get the Iteration number and store it in i
if(i==1)
 x=v;  // For the first iteration, x = VuserID
else
 x=6;  // For the second iterations onward, x = No of Vusers  + 1 (assuming Vusers = 5)
for(y=1;y<x;y++)
lr_advance_param(“CreatedCustID”);  // parameter file name (keep settings as Sequential Once)

————-

———-

———
return 0;
}

Loadrunner Custom Code to select more check box values


Note: checkboxvalueRaw is the list of correlated values which is being listed in the check boxes. It has to be checked in random numberr and submitted.

int i, j;

char checkboxvalue_param[100],temp_param[60], temp1_param[60];

web_reg_save_param(“checkboxvalueRaw”,”LB=XXXXX”,”RB=YYYYY”,”ORD=ALL”,”Notfound=warning”,LAST);

i=1;

j=(rand()%(atoi(lr_eval_string(“{checkboxvalueRaw_count}”)))+1);

lr_output_message (“i is %d, j is %d”, i,j);

do

{        sprintf (checkboxvalueRaw_param, “{checkboxvalueRaw_%d}”, i);

lr_save_string(lr_eval_string(checkboxvalueRaw_param), “checkboxvalue_sel”);

strcpy(temp_param, temp1_param);

strcat(temp_param, lr_eval_string(“{checkboxvalue_sel}”));

if (i<j)

{

strcat(temp_param, “,”);

}

strcpy(temp1_param, temp_param);

i=i+1;

}

while (i==j);

lr_save_string(lr_eval_string(temp_param), “checkboxvalue_sel”);

Loadrunner code to write a string in a file


char newvalue[15]=”I Love India”;
char *newvalue11,*newvalue12;
long pfile;
char *filename = “C:\\Sample.txt”;
newvalue11 = lr_eval_string(“{pFirstName}”);
newvalue12 = lr_eval_string(“{pLastName}”);
pfile = fopen( filename,”a+” );
if(pfile == NULL)
{
printf( “Error in opening the filename – %s “,filename );
}
fputs(newvalue,pfile );
fputs(“,”,pfile );
fputs(newvalue11,pfile);
fputs(“,”,pfile );
fputs(newvalue12,pfile);
fputs(“\n”,pfile );
fclose( pfile );

Access mode – Description:
r – Open an existing file for reading only.
w – Open a file for writing only. If the file does not exist create a new one. If the file exists it will be overwritten.
a – Open a file for appending only. If the file does not exist create a new one. New data will be added to the end of the file.
r+ – Open an existing file for reading and writing
w+ – Open a new file for reading and writing
a+ – Open a file for reading and appending. If the file does not exist create a new one.