LoadRunner VIDEO - How to record PDF file saving?

LoadRunner VIDEO - How to record PDF file saving?

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

42 comments:

P1 said...

Thanks Dmitri for answering this request in detail .

I have tried the example and as usual your demo rocks!! . I have never seen demo videos which such minute details.

I have 2 queries based on the post :
1] Normally if we do not use file handling and save it to explicit file , where is the data saved ? [default LR file for it] and is the data deleted after that particular user is terminated .

2] What was the significance of selecting: "A script containing explicit URLs only"

Great post!!

Unknown said...

I don't think this will be a very safe method in real life, with multiple vusers, as they will no doubt clash when trying to access that same file handle.

Perhaps you should parametize the file name using a combination of vuserid and a date time stamp to ensure you don't get a clash.

Food for thought.

Cheers,
Tim Koopmans

Dmitry Motevich said...

Tim, What do you mean with "this"?

In the video tutorial I explained how to download PDF-file with one virtual user in VuGen. It works!

At the end of presentation I accented attention, that the script should be modified for concurrent users. And I pointed to a possible solution how to generate unique file name.

If somebody ask, I will show how to generate unique file name for concurrent virtual users.

Kanda said...

Hi Dimitri ,its very useful and i checked that same ,its working fine.Thanks for your knowledge sharing

Kanda said...

Hi Dimitri,

I am kanda, working in LR9.0

I have 1 doubt regarding LR_Advance_Param functions for parameterization


I just ran the script with 2 iterations and Lr_advance_param functions as below
lr_output_message("Itera=%s","Param1=%s","param2=%s");
lr_eval_string("{param1}");
lr_eval_string("{param2}");
lr_advance_param("param1");

but for the above function,for 1 iteration itself,its taking 2 values(for both parameters) at a time.
May I know why its taking 2 values for 1 iteration itself.
Please check this replay log
Action.c(147): Notify: Parameter Substitution: parameter "Mail_To" = "kamal_vpm777@yahoo.co.in"
Action.c(148): Notify: Next row for parameter Mail_subject = 1 [table = Mail_subject].
Action.c(148): Notify: Parameter Substitution: parameter "Mail_subject" = "Hi"
Action.c(150): Notify: Next row for parameter Mail_To = 2 [table = Mail_To].
Action.c(150): Notify: Getting new value for parameter 'Mail_To': table = 'Mail_To.dat' column = '0' row = '2'.
Action.c(152): Notify: Parameter Substitution: parameter "Mail_To" = "kamalvpm777@gmail.com"
Action.c(152): Notify: Next row for parameter Mail_subject = 2 [table = Mail_subject].
Action.c(152): Notify: Getting new value for parameter 'Mail_subject': table = 'Mail_subject.dat' column = '0' row = '2'.
Action.c(152): Notify: Parameter Substitution: parameter "Mail_subject" = "Hi1"


I am waiting for response, hope i will get your suggestion asap

Kanda said...

Hi,

Is IP Spoofing is mandatory for VUsers in Controller?

1.See if we are running 50 users in controller, do we need to give 50 IPs in IP wizard?.
2.But Controller runs if we dont spoof any Ips,how its running,or is it a wrong way?
3.So can u give me your suggestion whether IP spoofing is required for Vusers or not?

With Regards,
Kanda

Anonymous said...

Hi...need to know in detail how can we have a unique name for the file if there are many concurrent users...plz reply to me soon...thanks

Anonymous said...

Hi...once again...can you please show how to generate unique file name for concurrent virtual users.....and also i need to remove the file after it gets generated....so can u plz provide me the solution...here's my mail id-lookwhoisin@gmail.com
Thanks...

TrojaN said...

Hi Dmitry,

This article is a very good example. But i am wondering if this same method can be used to replay a script in which i have recorded viewing an online pdf document.

After recording when i replayed it, it gave me an error saying it could not connect to the particular internet page.

can this method in ur blog be used for this?

Anonymous said...

Hi Dmitry,

Could you please tell me what do I need to do in my script to generate unique file name?

cheers
ALI
from Sydney - Austraia

Kanda said...

Hi Dmitri,

I tried this PDF saving for 1 user, its working fine.For Concurrent Vusers how can we use this script.So can you give me a idea how to generate unique filename for concurrent Vusers.In the file creation how can we paramaterize the filename.So please give me your suggestions


With Regards,
Kanda

Dmitry Motevich said...

2TrojaN:
You provided not enough information to answer your question.
I'm not a wizard and I can't read your thoughts...
-What LoadRunner script did you use?
-What error did you get?

srinivasun said...

I getting a Microsoft Visual C++ Runtime Library "Runtime Error" on the program C:\Program Files\Mercury\bin\vugen.exe. when i replay the scripts

Dmitry Motevich said...

2Srinu:
So, what's your question?

Anonymous said...

Hi Dmitry,

Howyagoin champ? my question is very simple. I have done scripting for an application where I save a PDF file. It's awesome when I use one Virtual user but let say I gotta use 10 Virtual User so I need a unique file name coz every Virtual can't open and write into the same file at the same time. What I want is every time when I run my script it should save a file with different a name. I know Loadrunner is not a tool to monitor client side activities but its good to know anyway.

u have a good one!

cheers

Ali
Sydney - Australia

Anonymous said...

Hi Dmitry,

thanks for sharing your knowledge in such a detail! I very often miss additional examples in the function reference. Saw this blog today for the first time but will surely come back ;)

Dmitry Motevich said...

2Ali from Sydney:
I have prepared articles on how to generate unique file name:
solution1
solution2

Dmitry Motevich said...

2Anonymous:
Thank you very much for reading!

Unknown said...

Hi Dmitry,
your explanation rocks! i am able to
save PDF file. no issues in that, but I have one issue:Can we create a script for just to open a PDF. As in my application we have a sealed media i.e Unsealer window login.So i am unable to capture the Unsealer window and open PDF.
I am waiting for your response, hope i will get your suggestion asap

Anonymous said...

Hey buddy,

I appreciate your knowledge and your command over LR.You are doing realy great job.At office in my free time your blog is my friend to me. Learning many things from you. Thanks Mr. virtual tutor.

Can you please also explain how to capture java script download i mean its an internal infrastructure dowload request to server to download .js in url.

Dmitry Motevich said...

2aniltheblogger.blogspot.com:
What do you mean with "capture java script download"?
Is it an answer?

Anonymous said...

It is the best video for explaining Loadrunner. Can you sililarly make a general video on "How To Use LoadRunner and it's different functions" for a novice like me ? I am into manual testing and in near future will use LR.

Dmitry Motevich said...

2bunty:
Provide more info on "Unsealer window login".

Unknown said...

Hi.
How to record pop ups in loadrunner

kama said...

Hi this is kamaraju.
thanks for sharing ur knowledge dmitry.good work
pls keep some more good topics where i can learn more topics on lr.

Dmitry Motevich said...

2aarthi,
I explained it here

Anonymous said...

hi Dmitri,
Thanks for explaining each and every topic in detail.I want to know whether any performance difference is there if an application runs on UNIX platform and WINDOWS operating system.please suggest that this environment is correct or not
java,jsp,html,jdbc,sqlserver,windows

Dmitry Motevich said...

to Anonymous (September 8),
What are your own guesses? :)

Unknown said...

Hi Dmriti,

I am very new to LR, I have the similer kind of requirement wherein we have to download the file (http download) from server and save it to client machine.

I have tried the code given by you for unique file name & the file download; it worked fine when with one Vuser, but when I try to use controller say for 10 concurrent users then only one file gets created that too with 0KB, do I need to do any setting in controller or Vugen to get it worked.

And one more question, if we have multiples files stored at server so in that case can we use Parameterization and download different files randomly.

Please help me out here.

Dmitry Motevich said...

to Niranjan (September 16),
You have to generate each downloaded files with its unique file names.
I have two posts on my blog. Please find - and you'll get a solution.

Regarding "multiples files stored at server". Actually, I didn't get you... Please, describe provide more details.

Unknown said...

Thanks Dmitry,

I am able to download the multiple files now !!

nithi said...

Active screen Problem
I am facing the active Screen in loadrunner
while runnning the script, active screen pop up is displaying, always asking for username and password.
This popup having OK,Cancel and HELP buttons.
After clicking any OK or CANCEL button , then only it is moving to next step
could u please give me any suggestion to solve this...

Dmitry Motevich said...

@nithi,
And what?

Anonymous said...

I would like to call you as automation master ji..... its wonder to see your blog videos. I m a beginner to load runner, it is helping me a lot ot learn loadrunner.Earlier I was afraid to learn and practise it but now i feel the confidence inside.

Master ji I have a doubt that, you have used some HP support codings for the part,"downloading and saving a PDF",i would be greatful if you could mail methe path to dhana.crazytester@gmail.com

Dmitry Motevich said...

@DD,
Please send your question to LoadRunner group.

Anonymous said...

Dmitri, I would like to know the secret that, which URL u have referred from Hp to copy the concept's Coding........please mail it to dhana.crazytester@gmail.com...........I would like to learn loadrunner from your blog, its amazing to have such a clear and wonderful demo of your's. You are reallly a Boon to automation testing !

Dmitry Motevich said...

@DD,
Sorry, I didn't understand your question about the link.
Re-read the above article. You can find the link there.

nithi said...

without displaying the pop up the script should be run

nithi said...

hi dmitry
without displayiny the pop up, script should run

Unknown said...

Hi Dmitry,

Thank you for your excellent job! I really do appreciate your work done on LoadRunner video tutorials. I am learning LoadRunner and your posts are useful to me getting required knowledge for LR. This blog is so useful to newbies and for those who are beginner in LR tool.

Keep up the good work in future!

Best Regards,

Hiten Dhruv

Anonymous said...

Hi,
This is excellent information. I have a similar scenario. I am working on IBM portal 6.0. We have a portlet which has some links. Clicking on the links will open dialog box to save zip file. The files are downloaded from secured location. I want to concurrently download the zip files.there can be more than one user and more than one link. Is there a way we can use loadrunner to perform te above scenario

Raam

A Rational Approach on Performance Engineering said...

Prabhu here.

Outstanding work Dmitri. Very useful. Thanks