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;
}

Performance Test DNS Servers using LoadRunner

If ever you need to use LoadRunner to test DNS servers, this is the script for you.

This virtual user script is designed to test hostname resolution against DNS servers. If a host address resolves to multiple addresses, all addresses are displayed in the output.   

N.B. DNS scripts use parameter delimiters rather than the more common {} delimiters.


 


#include “mic_socket.h”

 

Actions()

{

char *results = NULL;

int   rescnt  = 0;


lr_save_string(“10.190.32.16″,”DnsServer”); // Set DNS server IP Address

lr_save_string(“DNSSERVERNAME.CO.UK”, “Hostname”); // Set hostname to resolve


// Perform DNS Query

// Usage Notes:

// – IP Address of a Domain Name Server

//  – Name of host to resolve IP address for


results = (char *) ms_dns_query(“DnsQuery”,

“URL=dns://“,

“QueryHost=“,

LAST);


// List all the results… (if more than one)

while (*results) {

rescnt++;

lr_log_message(

lr_eval_string(“(%d) IP address for is %s”),

rescnt,

results);

results = (char *) ms_dns_nextresult(results);

}

return 0;

}