The LoadRunner Blog

Tuesday, November 21, 2006

File Download Test - getting downloaded file size

Giles on the SQAForum has given a code snippet to test for file download.
There are also a series of posts on the Loadrunner list that talks about how Loadrunner behaves in such a test. In short LR does not store a copy of the file , it just receives the packets and the data is then erased. You can however get the property of the files like download size, download time etc. Anyway back to Giles' solution


You simply call the function after the call to download the file.

Calling Action
Code:


Action()
{
web_url("GetPDF",
"URL=http://www.tfl.gov.uk/tfl/pdfdocs/colourmap.pdf",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Mode=HTML",
LAST);


/*Get File Statistics*/
funcFileDownload();


return 0;
}



Called Function:
Code:


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", fFileDownloadSize, fFileDownloadTime);
lr_output_message("Rate of download was %.2f KB/sec", fFileDownloadRate);

return 0;
}

Tuesday, November 07, 2006

XML Custom Requests - and Responses

Okay, if you are 'testing' XML pages rather than the regular HTTP pages - you can use lr_xml_find to text-check your responses. Recently I was required to code a test that sends an XML File to a service and gets a return XML file. The following is the code that works. You can program many variants of XML tests. Refer to Pages 1115-1128 of the VUGen guide "Programming with the XML API" for further details


The Code:


Action()
{
//Save XML Data into Character Variable
char *xml_input=
""
"WEB"
"100"
"1234567"
""
"VTEST"
"USD"
"4111123456789022"
"123"
"2012"
""
""
"8"
"9"
"2006"
"";

//Move Character Variable value into Parameter for LR
lr_save_string(xml_input,"XML_Input_Param");

//Capture all XML Data using WebRegSaveParam
web_reg_save_param("ServerXML", "LB=", "RB=", "Search=body", LAST);


/*Send Custom Request - using XML from XML_Input_Param in which char variable data has been saved */
web_custom_request("SendXML",
"URL=https://10.10.xxx.xxx:8080/authService",
"Method=POST",
"TargetFrame=",
"Resource=0",
"Referer=",
"Mode=HTTP",
"Body={XML_Input_Param}",
LAST);

//Converted XPath verifications
lr_xml_find("XML={ServerXML}",
"Query=/CCAuthResponse/responseCode",
"Value=1",
LAST );
return 0;
}