One LoadRunner user asked me -
How to record PDF file saving in LoadRunner?Earlier, I explained that
LoadRunner does not record client side activities!That means, that
LoadRunner records PDF file transferring ('cause it is a network activity) and
does not record PDF file saving (which does not generate any network traffic).
In some case, we need to save PDF (or other) file on local disk and process it (edit, parse, or compare with 'etalon' file).
The present LoadRunner video tutorial explains
how to record PDF file saving in LoadRunner.
How to record PDF file saving in LoadRunner? - LoadRunner video
This is a first LoadRunner script from the above
LoadRunner video tutorial.
Note: this script is based on
HP's article #11766 - How to verify download of a file in Web scripts (login to HP required to access).
int fp;
long i;
web_url("writings.html",
"URL=http://www.testing.com/writings.html",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
LAST);
//Truncate to zero length or create file for writing.
fp = fopen("c:\\temp\\my_file.pdf","wb");
//Set the parameter size large enough to save the data.
web_set_max_html_param_len("200000");
//Use web_reg_save_param with the correct boundary to capture the data returned by the server.
web_reg_save_param("FILED","LB=","RB=","Search=Body",LAST);
web_url("PDF",
"URL=http://www.testing.com/writings/automate.pdf",
"TargetFrame=",
"Resource=0",
"RecContentType=application/pdf",
"Referer=http://www.testing.com/writings.html",
"Snapshot=t2.inf",
"Mode=HTML",
LAST);
//Get the download size.
i = web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE);
//Write the data saved to an output file.
fwrite(lr_eval_string("{FILED}"), i, 1, fp);
//Close the file pointer.
fclose(fp);
As I shown in LoadRunner video, above script works incorrectly.
This is an
improved LoadRunner script which captures and saves PDF file correctly:
long fp;
char *data;
unsigned long prmLen;
web_url("writings.html",
"URL=http://www.testing.com/writings.html",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
LAST);
//Truncate to zero length or create file for writing.
fp = fopen("c:\\temp\\my_file.pdf","wb");
//Set the parameter size large enough to save the data.
web_set_max_html_param_len("200000");
//Use web_reg_save_param with the correct boundary to capture the data returned by the server.
web_reg_save_param("FILED","LB=","RB=","Search=Body",LAST);
web_url("PDF",
"URL=http://www.testing.com/writings/automate.pdf",
"TargetFrame=",
"Resource=0",
"RecContentType=application/pdf",
"Referer=http://www.testing.com/writings.html",
"Snapshot=t2.inf",
"Mode=HTML",
LAST);
//Get the download size.
lr_eval_string_ext("{FILED}", strlen("{FILED}"), &data, &prmLen, 0, 0, -1);
//Write the data saved to an output file.
fwrite(data, prmLen, 1, fp);
//Close the file pointer.
fclose(fp);
Related articles:
Do you like this LoadRunner visual tutorial? Would you like to receive them in the future?
If yes, please subscribe to this blog RSS feed or by Email. (How to subscribe? VIDEO guide)
--
Dmitry Motevich