Parameter i JSON request body pointing to .csv file

Hello,
I have a JSON request body looking like this:

`
{“offerId”: “${offerId}”, “membershipId”: “${memberID}”, “osName”: “Android”, “osVersion”: “4.4”}

`

and a testdata file with this content:

`

memberID,offerId
8107222059,000C297765971EE495BE0BA921A125F7
8107222052,000C297765971EE495BE0BA921A125F7

`

`

val scn = scenario(“Scenario”)

.feed(csv(“memberInfo.csv”).random)

.exec(_.set(“TOKEN”, “${memberID}”))

.exec(
http(“buyGift”)
.post("/gift/buy")
.header(“X-Token”, “${TOKEN}”)
.body(ELFileBody(“buyGift.json”)).asJSON
.check(status.is(200))
.check(jsonPath("$.resultCode").is(“SUCCESS”))
)

}

`

But when I enable logging the log states:

`

Request:
getProfile: OK

Hi Magnus,

When you set manually a value in the session using set(name, value), like you did with .exec(_.set(“TOKEN”, "${memberID}”)), value cannot be a EL string.
But then, why don’t simply write .header(“X-Token”, “${memberID}”) ?

Cheers,

Pierre

Hi Pierre,
Ok, but will Gatling then use the same line in my testdatafile when I do like below? Will the two highlighted red ${memberID} refer to the same row in the testdatafile?

`

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._

class XSimulation extends Simulation {

val httpConf = http
.baseURL(“https://myapp.sweet.se”)
.acceptEncodingHeader(“gzip,deflate”)
.headers(Map(“Content-Type” → “application/json”, “charset” → “UTF-8”, “User-Agent” → “Android(4.4)/Sweet(0.4)/0.1”))

val scn = scenario(“Scenario”)

.feed(csv(“memberInfo.csv”).random)

.exec(
http(“getProfile”)
.get("/user/profile")
.header( “X-Token”, “${memberID}” )
.check(status.is(200))
.check(jsonPath("$.resultCode").is(“SUCCESS”))
)

.exec(
http(“getGiftList”)
.get("/gift/all")
.header(“X-Token”, “${memberID}”)
.check(status.is(200))
.check(jsonPath("$.resultCode").is(“SUCCESS”)))

setUp(scn.inject(constantUsersPerSec(1) during (1 minutes))).protocols(httpConf)

}

`

Short answer: yes.
Long answer: yes, as long as you do not add another .feed(csv(“memberInfo.csv”).random) between your execs.

and if I have a json-body like this:

`

{“offerId”: “${offerId}”, “membershipId”: “${memberID}”, “osName”: “Android”, “osVersion”: “4.4”}

`

I can say:

`

.exec(
http(“activateGift”)
.post("/gift/activate")
.header(“X-Token”, “${memberID}”)
.body(ELFileBody(“activateGift.json”)).asJSON
.check(status.is(200))
.check(jsonPath("$.resultCode").is(“SUCCESS”))
)

`

and it will pick up memberID first as a header and then as a value inside my request (json-body), both being the same row in the testdata .csv file? right.

I can use it both as a direct parameter within my exec ( .header(“X-Token”, “${memberID}”)) and inside son body like this:

{“offerId”: “${offerId}”, “membershipId”: “${memberID}”, “osName”: “Android”, “osVersion”: “4.4”}

?

Magnus

Yes you can.
As long as you do not add another feed(…) call in your scenario, the same record will be used throughout the scenario, as many times as you want.