Saturday, April 27, 2024

How to Save the downloaded file to local system in load runner

In certain scenarios, downloading files becomes a requirement. Instead of needing to store the files on your local machine for later verification, you may want to measure the transaction time of the download process. To do this, you can capture data from the server response and save it to a file using standard file operations. Just be sure you know the type of file you will be downloading.

Here's an example of downloading a `.pdf` file and saving it to your local system:


// Declare variables
int filePointer;
long fileSize;

// Create a file for writing
filePointer = fopen("c://test_file.pdf", "wb");

// Start a transaction to measure download time
lr_start_transaction("file_download");

// Increase the parameter size to accommodate the data
web_set_max_html_param_len("100000");

// Use web_reg_save_param with the appropriate boundaries to capture server response data for the download
web_reg_save_param("FILEDATA", "LB=", "RB=", "Search=Body", LAST);

// HTTP request to download the .pdf file
web_url("http://serverURL:port/app/resource/getme.pdf");

// Retrieve the download size
fileSize = web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE);

// Write the captured data to an output file
fwrite(lr_eval_string("{FILEDATA}"), fileSize, 1, filePointer);

// End the transaction
lr_end_transaction("file_download", LR_AUTO);

// Close the file
fclose(filePointer);

This code snippet demonstrates how to use file operations and LoadRunner functions to download a PDF file from a server, capture the download data, save it to a local file, and measure the transaction time. By following this process, you can efficiently analyze the download performance without needing to store the downloaded files on your machine for later verification.