How to download files using Apache JMeter?

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 the Author

3 thoughts on “How to download files using Apache JMeter?”

  1. 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
  2. I was able to download the file based on the configuration in the Save Response to File, but I end up getting a blank .xls file when downloaded. When I click on the Export button it automatically download the file. What is the additional step I need to do to capture the data?

    Reply
  3. I am able to download file using “Save Responses to a file” listner.
    My application uses javascript:__doPostBack(‘xyz’, ”) function , I have handled __VIEWSTATE, __VIEWSTATEGENERATOR, and __EVENTVALIDATION. and few more arguments.

    Thanks Naveen

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Hamster - Launch JMeter Recent Test Plans SwiftlyDownload for free
+
Share via
Copy link