Close

April 18, 2015

How to download files using Apache JMeter?

POST Request

When I started learning performance testing couple of years ago, I was skeptical about how to download files using Apache JMeter or HP LoadRunner. Downloading files is pure client side activity. When you click on the file name or Download button, pop-up would generate from the OS. Once you click on Open or Save button, the file will get stored in your local disk.

E.g. In below snapshot, when you click on the attachment, you would get a Save As dialog box.

Attachment

Attachment

Save As

Save As

To download attachment using Apache JMeter, add a HTTP Request Sampler as shown below.

HTTP Request

HTTP Request

When you execute the test plan, in View Results Tree, you can see below response data from the server.

Response Data

Response Data

This will not download the desired file to your local disk. We will see how to download files using Apache JMeter.

To download files, you need to add Save Responses to a file sampler to your test plan. Below are my settings in my test plan.

Save Responses to a file

Save Responses to a file

Now execute the test plan and go to your JMETER_FOLDER\bin\. You could see the attachment which got downloaded as shown below.

Download Attachment

Download Attachment

Above approach is pretty simple, because we have the direct URL to download the file. What if the application has javascript doPostBack links? You cannot see or track the actual URLs when you click on the URLs. Actual links will look like javascript:__doPostBack(‘Page1′,’2’)

What is javascript__doPostBack function?

Javascript__doPostBack function has two arguments EVENTTARGET and EVENTARGUMENT. Those two arguments will automatically declared. The value of the two arguments will store in a hidden fields. You can get the values from the source code.

EVENTTARGET has which control triggered the action. E.g. when you click on Link 1, the id of the control Link 1 will get passed in the __doPostBack function.

EVENTARGUMENT has additional data associated with the control i.e. in this case, it will trigger the download process.

If you see in this http://stackoverflow.com/questions/12501510/how-to-download-and-store-a-txt-file-behind-a-javascript-link , if you mouse hover on the download link, you could see javascript:__doPostBack(‘ctl00$ContentPlaceHolder1$hlPreReleaseAll’, ”)

In this case, you will not have direct link to download the files from the website. When you click on the link, doPostBack function triggers with the control and the argument. It is not the GET call, it is POST call. In the JMeter test plan, you need to add HTTP Request Sampler for POST call and pass at least two arguments as shown below.

  1. __EVENTTARGET
  2. __EVENTARGUMENT

Usually I use Fiddler tool to identify what value is being passed. In some instances, you may need to pass following arguments: __VIEWSTATE, __VIEWSTATEGENERATOR, and __EVENTVALIDATION.

POST Request

POST Request

If you execute the script, you can see the file which you want to download will get stored in the bin folder. To download the script, please create a pull request at https://github.com/QAInsights/JMeter-Script

NOTE: The above script has been created only for educational purpose, do not use in the production application/site/URL. Use at your risk, we are not responsible for any consequences.

About NaveenKumar Namachivayam

Hi there! is a passionate and experienced Performance Test Analyst based in Chicago, USA with skill sets in Manual Testing, Test Automation, Performance Testing, and Test Estimation. He loves to learn and experiment new trends and models in Software Testing. Please stop by at his personal blogs: Excel Blog, DealsBrook, NaveenKumarN.in, and Affiliate Insights blog and Software Testing Memes.

One Comment on “How to download files using Apache JMeter?

Srini
October 17, 2015 at 1:36 am

Hi naveen,
I am trying to Captureto click a link and save it .But when i try to run it’s not able to store the pdf file in Bin folder.

Reply

Leave a Reply

Your email address will not be published. Required fields are marked *