Adding a request (json) body in a simualtion

Hello,
I am using ELFileBody to feed my simulation with data like this:

`

class LoginSimulation extends Simulation {

val httpConf = http
.baseURL(https://mysite.start.com)
.acceptEncodingHeader(“gzip,deflate”)
.baseHeaders(Map(“X-Token” → “1234asdf”, “Content-Type” → “application/json”, “charset” → “UTF-8”))

val scn = scenario(“Scenario”)

.exec(
http(“activateUser”)
.post("/user/activate")
.body(ELFileBody(“activateUser.txt”))
.check(status.is(200))
.check(jsonPath("$.resultCode").is(“SUCCESS”)))

`

The file “activateUser.txt” looks like this:

{"offerId": "123", "membershipId": "123", "osName": "iOS", "osVersion": "8.02"}

Can I just add lines in the file like this:

{"offerId": "123", "membershipId": "123", "osName": "iOS", "osVersion": "8.02"} {"offerId": "124", "membershipId": "124", "osName": "iOS", "osVersion": "8.02"} {"offerId": "125", "membershipId": "125", "osName": "iOS", "osVersion": "8.02"} {"offerId": "126", "membershipId": "126", "osName": "iOS", "osVersion": "8.02"}

and how do I tell Gatling to change to the next line in the test datafile?

Magnus

If I do not want to use ELFile but just plain parameters how can I say:

{“offerId”: “123”, “membershipId”: “123”, “osName”: “iOS”, “osVersion”: “8.02”}

in the body part below?

.exec( http("activateCoupon") .post("/coupon/activate") .body("?") .check(status.is(200)) .check(jsonPath("$.resultCode").is("SUCCESS")))

can I say

.body("{"offerId": "${param1}", "membershipId": "${param2}", "osName": "iOS", "osVersion": "8.02"}")

and refer to i.e. .csv files in my project?

Magnus

Absolutely.
ELFileBody is for templating.

Can I also refer a parameter inside the template?
Given a template file with contents like:

{“offerId”: “123”, “membershipId”: “123”, “osName”: “iOS”, “osVersion”: “8.02”}

can I say

{“offerId”: “123”, “membershipId”: “${memberID}”, “osName”: “iOS”, “osVersion”: “8.02”}

and refer to a csv file I have?
So then I first refer the template (.body(ELFileBody(“activateCoupons.json”)).asJSON), then I refer the .csv file form the template (“membershipId”: “${memberID}”), and then I have a .csv file looking like this:

memberID
123
124
125
126

?

If I want more colums in my tesdata .csv file can I just use a Space between them like this:

memberID, offerId
123, 123
124, 124
125, 125
126, 126

Thank you!

So then I first refer the template
(.body(ELFileBody("activateCoupons.json")).asJSON), then I refer the .csv
file form the template ("membershipId": "${memberID}"), and then I have a
.csv file looking like this:

memberID
123
124
125
126

Yeah, of course, that's what ELFileBody is for.
Try it for yourself.

If I want more colums in my tesdata .csv file can I just use a Space
between them like this:

memberID, offerId
123, 123
124, 124
125, 125
126, 126

No space. CSV doesn't imply trimming the values.

Sweet, it is working great!