How-to verify file downloaded

Posted: August 28th, 2009 | Author: TnT Admin | Filed under: How-Tos | Tags: , | No Comments »

Often there is a need to verify the validity of the file being downloaded by the script.  Under normal circumstances, if the file is a PDF or excel file, it will be returned/transmitted in binary (when you turned on replay log).  In this way, unlike conventional functional tool, LoadRunner is unable to verify if the file downloaded is valid.

In order to circumvent that, we use web_get_int_property API to retrieve the file size.  This file size will then be used to make comparison with the actual known file size on the server.  For usage of web_get_int_property, you can refer to the Function Reference available in Vugen.

On a brief overview, place the web_get_int_property APT after the request (web_url, web_custom_request, etc.) made for the file (PDF/excel).  I’ve extracted examples from LoadRunner Yahoo Groups and list them below for your convenience.

Example 1:

lr_message(“%ld”,web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE));

web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE);

web_get_int_property(HTTP_INFO_DOWNLOAD_TIME);

Note, HTTP_INFO_DOWNLOAD_SIZE does not give the actual size of PDF file.  This HTTP_INFO_DOWNLOAD_SIZE gets the body bytes, header bytes, and chunk bytes.  Therefore, you may need to fine tune the script to determine a range value of the PDF file size due to the header and chunk bytes.

Example 2:

float fFileDownloadSize, fFileDownloadTime, fFileDownloadRate;

funcFileDownload()
{
fFileDownloadSize = (web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE)/1024.);
//in kilobytes
fFileDownloadTime = (web_get_int_property(HTTP_INFO_DOWNLOAD_TIME)/1000.);
//in seconds
fFileDownloadRate = fFileDownloadSize/fFileDownloadTime; //in KB/s

lr_output_message(“Size of download was %.0f kilobytes; Time of download was %.3f seconds”, FileDownloadSize, fFileDownloadTime);

lr_output_message(“Rate of download was %.2f KB/sec”, fFileDownloadRate);

return 0;
}

Example 3:

long DSize=0;

float DTime=0;

DSize = web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE);

lr_output_message(“DSize is: %.2ld Bytes”, DSize);

lr_output_message(“File Download size is: %.2ld KB”, DSize /1024);

DTime = web_get_int_property(HTTP_INFO_DOWNLOAD_TIME);

lr_output_message(“File Download Time is:%.2f Seconds”, DTime / 1000);

Related Posts


Comments are closed.