LoadRunner function to strip leading zeroes from date

//Use this function to remove the preceding 0’s from the date.
//Displays the date 05/07/2005 as 5/7/2005.

Date_function()
{
char *DayDate, *MonthDate, *YearDate;

lr_save_datetime(“%d”, DATE_NOW, “CurrentDay”);
lr_save_datetime(“%m”, DATE_NOW, “CurrentMonth”);
lr_save_datetime(“%Y”, DATE_NOW, “CurrentYear”);

DayDate= lr_eval_string(“{CurrentDay}”);
MonthDate= lr_eval_string(“{CurrentMonth}”);
YearDate= lr_eval_string(“{CurrentYear}”);

if (strcmp(DayDate,”10″)<0){DayDate = DayDate+1;}
else {DayDate = DayDate;}

if (strcmp(MonthDate,”10″)<0){MonthDate = MonthDate+1;}
else {MonthDate = MonthDate;}

lr_output_message (“Date is %s/%s/%s”, DayDate,MonthDate,YearDate); // Outputs message to the LR log.

}

Write Data to an external file in LoadRunner

This script shows how you can write data to an output file in LoadRunner.

 

Writes to file called “C:\Temp\Write_To_File_Demo_%s.txt”

 


 

long outstream = 0; 
 char OutputFile[1024] = "";        
 
 Action()
 {
     lr_save_datetime("%y%m%d", DATE_NOW, "FileDate"); 
     lr_save_datetime("%y/%m/%d", DATE_NOW, "Date"); 
     lr_save_datetime("%H:%M", TIME_NOW, "Time"); 
     
     sprintf(OutputFile,"C:\\Temp\\Write_To_File_Demo_%s.txt",
     lr_eval_string("{FileDate}"));
     
     outstream = fopen (OutputFile,"a+");
     
     if (outstream == NULL)
     lr_output_message ("Could not open output file %s",OutputFile);
     
     else 
     {
     fprintf (outstream, "This line written during Iteration %s, at %s on %s. \r\n",
     lr_eval_string("{Iteration}"),
     lr_eval_string("{Time}"),
     lr_eval_string("{Date}"));
     fclose (outstream);
     }
     
     return 0;
 }

 

 

LoadRunner function to measure size of downloaded file

This function can be used to measure the size of a downloaded file. It uses the LoadRunner lr_user_data_point function to save the downloaded file size into the results set. The size of these files can then be plotted as part of the results set or be displayed in the controller during a performance test.

Solution:
Use web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE); after the call to download the resource (this captures the size of the downloaded file).

iDLSize = web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE);

Next report that to the scenario through a user point.

lr_user_data_point(“DownLoadSize”, iDLSize);

Here is a sample script:


vuser_init()
{
int iDLSize=0;

web_url(“index.php”, 
“URL=http://192.168.38.200/kb_portal/index.php?action=dlattach;topic=54.0;attach=21”, 
“TargetFrame=”, 
“Resource=1”, 
“RecContentType=application/octet-stream”, 
“Referer=”, 
“Snapshot=t1.inf”, 
LAST);

iDLSize = web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE);

lr_user_data_point(“DownLoadSize”, iDLSize);

return 0;
}