# How to ensure a pdf is downloaded during a loadtest?

**URL:** <https://community.gatling.io/t/how-to-ensure-a-pdf-is-downloaded-during-a-loadtest/3927>\
**Category:** Gatling (Open-Source)\
**Created:** [September 12, 2017, 8:35am UTC](https://community.gatling.io/t/how-to-ensure-a-pdf-is-downloaded-during-a-loadtest/3927 "2017-09-12T08:35:38Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Reetu\_Pandita](https://avatars.discourse-cdn.com/v4/letter/r/9fc348/32.png) [@Reetu\_Pandita](https://community.gatling.io/u/Reetu_Pandita)\
**Post date:** [September 12, 2017, 8:35am UTC](https://community.gatling.io/t/how-to-ensure-a-pdf-is-downloaded-during-a-loadtest/3927/1 "2017-09-12T08:35:38Z")

</div>

Hi,

I have a script where two requests are triggered when I mimic click on a download button. Manually if I do it in UI it works fine and the file is downloaded into my local. However, if  
I try the same via script gatling shows everything works fine but the file is not present in my local.

The two requests are as follows:

exec(  
http(“S3.1 - get.php download simple”)  
.post("/participant/controller/flow/get.php")  
.formParam(“action”, “111”)  
.formParam(“fileId”, “${simpleFileId}”)  
.formParam(“containerId”,"${simpleContainerId}")  
.formParam(“flowId”, “${testId}”)  
.formParam(“csrfId”, “${csrfId}”)  
.check(  
status.is(200)))

.exec(  
http(“S3.2 - newset.php action 308 simple”)  
.post("/participant/controller/flow/newset.php")  
.formParam(“flowId”, “${testId}”)  
.formParam(“action”, “308”)  
.formParam(“value[userid]”,"${testInf.userId}")  
.formParam(“csrfId”, “${csrfId}”)  
.check(  
status.is(200)  
))

I did some reading related to other performance tools and it suggests setting response headers content-disposition: attachment or content-type: pdf/application. However, in the application Is there a way by which I can save the response header and change it so that the file will get downloaded? For the new header do I need to send a fresh request?  
Thanks in advance

---

<div class="post-metadata">

**Author:** ![Murthy\_N](https://avatars.discourse-cdn.com/v4/letter/m/76d3ee/32.png) [@Murthy\_N](https://community.gatling.io/u/Murthy_N)\
**Post date:** [May 12, 2019, 8:16am UTC](https://community.gatling.io/t/how-to-ensure-a-pdf-is-downloaded-during-a-loadtest/3927/2 "2019-05-12T08:16:23Z")

</div>

Hi Reetu,

How did you achieve this? I have a same scenario. If someone can post solution that would be more helpfull.

Thanks.

---

<div class="post-metadata">

**Author:** ![Prad](https://avatars.discourse-cdn.com/v4/letter/p/8e7dd6/32.png) [@Prad](https://community.gatling.io/u/Prad)\
**Post date:** [July 28, 2022, 8:49am UTC](https://community.gatling.io/t/how-to-ensure-a-pdf-is-downloaded-during-a-loadtest/3927/3 "2022-07-28T08:49:51Z")

</div>

Hi,  
I am trying to achieve similar scenario with my application.  
Did you find the solution for this.

Thanks,  
Prad

---

<div class="post-metadata">

**Author:** ![sbrevet](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/sbrevet/32/830_2.png) [@sbrevet](https://community.gatling.io/u/sbrevet)\
**Post date:** [July 28, 2022, 11:04am UTC](https://community.gatling.io/t/how-to-ensure-a-pdf-is-downloaded-during-a-loadtest/3927/4 "2022-07-28T11:04:21Z")

</div>

Hi all!

You can try [`bodyBytes`](https://gatling.io/docs/gatling/reference/current/core/check/#bodybytes) or [`bodyStream`](https://gatling.io/docs/gatling/reference/current/core/check/#bodystream) in the check section.

Cheers!

---

<div class="post-metadata">

**Author:** ![GeMi](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/gemi/32/939_2.png) [@GeMi](https://community.gatling.io/u/GeMi)\
**Post date:** [July 28, 2022, 7:45pm UTC](https://community.gatling.io/t/how-to-ensure-a-pdf-is-downloaded-during-a-loadtest/3927/5 "2022-07-28T19:45:42Z")

</div>

Below you have Example in Java:

```auto
import io.gatling.javaapi.core.ScenarioBuilder;
import io.gatling.javaapi.core.Simulation;
import io.gatling.javaapi.http.HttpProtocolBuilder;

import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.javaapi.http.HttpDsl.http;

public class PDFdownloadSimulation extends Simulation {

   // https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf
    HttpProtocolBuilder httpProtocol =
            http
                    .baseUrl("https://www.w3.org");

    ScenarioBuilder scn =
            scenario("Scenario Name")
                    .exec(
                            http("request_1")
                                    .get("/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf")
                                    .check(bodyBytes().is(RawFileBody("dummy.pdf")))
                                    .check(bodyLength().is(13264))
                    );

    {
        setUp(scn.injectOpen(atOnceUsers(1)).protocols(httpProtocol));
    }
}

```

---

<div class="post-metadata">

**Author:** ![Prad](https://avatars.discourse-cdn.com/v4/letter/p/8e7dd6/32.png) [@Prad](https://community.gatling.io/u/Prad)\
**Post date:** [July 29, 2022, 8:01am UTC](https://community.gatling.io/t/how-to-ensure-a-pdf-is-downloaded-during-a-loadtest/3927/6 "2022-07-29T08:01:13Z")

</div>

Hi all,  
I send a (.json) request from gatling script which in response downloads the file.

I have logback.xml settings to capture this response in a log file. Here, I could see the file contents are derived as part of the session value in a List in a Log file. This confirms the file is downloaded with each user request.

My query is, how could we get the physical file on the disk or in downloads folders with each iteration.

Appreciate your support.

Thanks,  
Prad

---

<div class="post-metadata">

**Author:** ![sbrevet](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/sbrevet/32/830_2.png) [@sbrevet](https://community.gatling.io/u/sbrevet)\
**Post date:** [July 29, 2022, 9:54am UTC](https://community.gatling.io/t/how-to-ensure-a-pdf-is-downloaded-during-a-loadtest/3927/7 "2022-07-29T09:54:35Z")

</div>

Since you receive your content, you can [write it on file](https://www.baeldung.com/java-write-to-file).

I’m curious, why do you need your files on disk? As Gatling is a load testing tool, at high usage your disk will be empty (and performance of writing on disk is very poor)

---

<div class="post-metadata">

**Author:** ![Prad](https://avatars.discourse-cdn.com/v4/letter/p/8e7dd6/32.png) [@Prad](https://community.gatling.io/u/Prad)\
**Post date:** [July 29, 2022, 11:01am UTC](https://community.gatling.io/t/how-to-ensure-a-pdf-is-downloaded-during-a-loadtest/3927/8 "2022-07-29T11:01:06Z")

</div>

Sure, Thanks for the update.

Basically, I had run similar scenario in JMeter, there we used plugin “Save Responses to a file” which was able to download .pdf file and save to bin folder. So I was thinking if we have something similar in Gatling.

Thanks,  
Prad
