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
Try the following
.body(RawFileBody(“ccp/ccpupload/send_request.json”))
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”))
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
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.