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

No comments:

Post a Comment