Monday, December 10, 2012

Loadrunner How to Download an Image

Usually images such as jpg, gif, png, etc., will be downloaded automatically as extra resources.  However, occasionally it is necessary to download images directly.  Downloading an image directly can be done easily as follows:
  • make web_url call requesting jpg, gif, png, etc.
  • Set Resource=1 indicating the the downloaded item is a resource
  • Use content type/mime type "image/jpg", "image/gif", "image/png", etc.
The following script illustrates this method as follows:
  • Image of type png is downloaded
  • Downloaded image file size is retrieved and checked that it is as expected.
  • Script writes an error message is the downloaded size is not as expected.

Script


Action()
{
long imgSize=0;

web_url("test pdf download",    
"URL=http://www.google.com/images/nav_logo114.png",
"Resource=1",
"RecContentType=image/png",
"Snapshot=t1.inf",
LAST);

    // Save pdf file size
imgSize = web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE);

// Verify size is as expected (~28765 bytes 321 header bytes)
if (imgSize < 28765 ) {
lr_error_message("File download error, expected ~247,800 bytes but got %d", imgSize);
} else {
lr_output_message("File downloaded size okay, expected ~247,800 bytes and got %d", imgSize);
}

return 0;
}

Console Output


Running Vuser...
Starting iteration 1.
Starting action Action.
Action.c(6): web_url("test pdf download") was successful, 28765 body bytes, 321 header bytes   [MsgId: MMSG-26386]
Action.c(14): web_get_int_property was successful   [MsgId: MMSG-26392]
Action.c(20): File downloaded size okay, expected ~247,800 bytes and got 29086
Ending action Action.
Ending iteration 1.
Ending Vuser...

Friday, December 7, 2012

Loadrunner How to Download PDF File

A pdf file can be downloaded in loadrunner as follows:

  • make web_url call requesting pdf
  • Set Resource=1 indicating the the downloaded item is a resource
  • Use content type/mime type "application/pdf"
The following script illustrates this method as follows:
  • Pdf is downloaded
  • Downloaded pdf file size is retrieved and checked that it is as expected.
  • Pdf file contents is saved to a parameter

Script

Action()
{
long pdfSize=0;

web_reg_save_param("pdfContent", 
"LB=", 
"RB=", 
LAST );

web_url("test pdf download",    
"URL=http://research.google.com/archive/disk_failures.pdf",
"Resource=1",
"RecContentType=application/pdf",
"Snapshot=t1.inf",
LAST);

    // Save pdf file size
pdfSize = web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE);

// Verify size is as expected (~247808 bytes)
if (pdfSize < 247000) {
//End the transaction
lr_error_message("File download error, expected ~247,800 bytes but got %d", pdfSize);
} else {
lr_output_message("File downloaded size okay, expected ~247,800 bytes and got %d", pdfSize);
}


lr_output_message("pdfContent=%s", lr_eval_string("{pdfContent}"));

return 0;
}

Console Output

Starting action Action.
Action.c(6): Registering web_reg_save_param was successful   [MsgId: MMSG-26390]
Action.c(11): Redirecting "http://research.google.com/archive/disk_failures.pdf" (redirection depth is 0)   [MsgId: MMSG-26694]
Action.c(11): To location "http://static.googleusercontent.com/external_content/untrusted_dlcp/research.google.com/en/us/archive/disk_failures.pdf"   [MsgId: MMSG-26693]
Action.c(11): web_url("test pdf download") was successful, 247808 body bytes, 715 header bytes   [MsgId: MMSG-26386]
Action.c(19): web_get_int_property was successful   [MsgId: MMSG-26392]
Action.c(26): File downloaded size okay, expected ~247,800 bytes and got 248523
Action.c(30): pdfContent=HTTP/1.0 302 Found
Location: http://static.googleusercontent.com/external_content/untrusted_dlcp/research.google.com/en/us/archive/disk_failures.pdf
Cache-Control: private
Content-Type: text/html; charset=UTF-8