I recently took some interest in learning some load testing tools and Gatling seemed a very good choice. The only drawback related to other tools is the lack of documentation/examples for the upload of files with dynamic values.
For example, to upload a static CSV file I can use:
val scn: ScenarioBuilder = scenario("My First Test")
.exec(http("Upload CSV")
.post("/csv-upload")
.formUpload("file", "file.csv")
.check(status.is(202))
)
But if I want to add a feeder to add values to that CSV I would like to have something like:
val scn: ScenarioBuilder = scenario("My First Test")
.feed(customFeeder)
.exec(http("Upload CSV")
.post("/csv-upload")
.formUpload("file", ElFileBody("file.csv"))
.check(status.is(202))
)
I already tried multiple methods to upload body parts and for example, if I do something of the sort:
val scn: ScenarioBuilder = scenario("My First Test")
.feed(customFeeder)
.exec(http("Upload CSV")
.post("/csv-upload")
.bodyPart(ElFileBodyPart("file", "file.csv"))
.check(status.is(202))
)
I get an error on the server-side:
MissingServletRequestPartException: Required request part 'file' is not present
I was able to proxy the request that Gatling does and the generated curl request is:
curl --location --request POST 'http://localhost:8080/api/v1/resource/csv' \
--header 'accept: application/json' \
--header 'content-length: 310' \
--header 'content-type: multipart/form-data; boundary=UhyANQVVCm0hahnV9JvGEA8tPLU1Kc2Z5Fj' \
--header 'host: localhost:8080' \
--header 'x-tenantid: t1' \
--data-raw '--UhyANQVVCm0hahnV9JvGEA8tPLU1Kc2Z5Fj
Content-Disposition: form-data; name="file"
Content-Type: multipart/form-data; charset=UTF-8
Name,Phone,Address
PersonName,123456,ThatStreet
--UhyANQVVCm0hahnV9JvGEA8tPLU1Kc2Z5Fj--
'
Which constructs the request correctly, but the error on the server side remains.
Is there any way that this can be achievable?
No idea where this comes from.
.formUpload("name", "path")
is merely a handy shortcut forbodyPart(RawFileBodyPart("name", "path"))
.Please read the official documentation regarding multipart support.