rawFileBody and rawFileBodies

23 views
Skip to first unread message

Raghav Pal

unread,
Jan 15, 2022, 2:40:54 AM1/15/22
to Gatling User Group
I am using latest Gatling 3.7.3 (open source)
I am trying to create a POST request and need to get the json body (payload) from a file

val scn = scenario("Post API Demo")

  .exec(
    http("Create User")
      .post("/users")
      .asJson
      .header("content-type", "application/json")
      .body(rawFileBodies("./data/createuserdata.json")).asJson

As per the documentation we can use rawFileBody function, but it is not available instead we have rawFileBodies, how to use it and what will be the best way to get request body from file

Bharath Marrivada

unread,
Jan 15, 2022, 4:46:12 AM1/15/22
to Gatling User Group
Try the following
.body(RawFileBody("ccp/ccpupload/send_request.json"))

Bharath Marrivada

unread,
Jan 15, 2022, 5:50:47 AM1/15/22
to Gatling User Group
I am using Java 17, Gatling 3.7.3, IntelliJ, Windows. Following is the sample code.

http("Create User")
.post("/users")
.header("content-type", "application/json")
.body(RawFileBody("ccp/data/createuserdata.json.json"))

On Saturday, January 15, 2022 at 1:10:54 PM UTC+5:30 test.ra...@gmail.com wrote:

slan...@gatling.io

unread,
Jan 15, 2022, 5:59:00 AM1/15/22
to gat...@googlegroups.com
In short :
1. The documentation states RawFileBody with a capital R.
3. The documentation states to use a classpath path, not a relative filesystem path

RawFileBody("data/createuserdata.json")


Le 15 janv. 2022 à 11:50, Bharath Marrivada <bharath....@gmail.com> a écrit :

I am using Java 17, Gatling 3.7.3, IntelliJ, Windows. Following is the sample code.
--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gatling/5262d70b-840c-42ea-ac0a-7dd1f53c5ac8n%40googlegroups.com.

Raghav Pal

unread,
Jan 20, 2022, 1:35:51 AM1/20/22
to Gatling User Group
Thanks a lot for the help Bharath and Stéphane.
The issue was indeed the use of capital R, it would have been great if it shows the options in auto-suggestion list
Other thing is, I was able to run with relative path as shown below

.body(RawFileBody("data/createuserdata.json"))

Here, data folder is under src/test/resources, hope can help others

Raghav


Stéphane LANDELLE

unread,
Jan 20, 2022, 4:21:52 AM1/20/22
to gat...@googlegroups.com
> Other thing is, I was able to run with relative path as shown below

Making things clear: no, "data/createuserdata.json" is not a relative path on the filesystem.
This is a Java classpath location. And the classpath separator is always "/" whatever the OS, even on Windows.


--

Stéphane Landelle

Chief Technical Officer

   

slan...@gatling.io
gatling.io
   
facebook twitter linkedin 


Reply all
Reply to author
Forward
0 new messages