Parameter i JSON request body pointing to .csv file

210 views
Skip to first unread message

Magnus Jensen

unread,
Nov 17, 2014, 9:59:05 AM11/17/14
to gat...@googlegroups.com
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 
=========================
Session:
Session(Scenario,354820329020934272-2,Map(memberID -> 1361300128, offerId -> 000C297765971EE495BE0BA921A125F7, TOKEN -> ${memberID}, gatling.http.cache.etagStore -> Map(https://myapp.sweet.se/user/profile -> "KXHNPNILBKTUOSY")),1416233886732,0,OK,List(),<function1>)
=========================
HTTP request:
headers=
X-Token:  ${memberID}
charset: UTF-8
Content-Type: application/json
Accept-Encoding: gzip,deflate
User-Agent: Android(4.4)/Sweet(0.4)/0.1
Connection: keep-alive
Accept: */*
=========================
HTTP response:
status=
200 OK
headers= 
Age: [19461]
Date: [Mon, 17 Nov 2014 08:53:46 GMT]
Connection: [Keep-Alive]
ETag: ["KXHNPNILBKTUOSY"]
Content-Type: [application/json;charset=UTF-8]
Content-Length: [223]
Server: [Jetty(9.2.4.v20141103)]

body=

I expect the request to have the actual memberId as parameter, not ${memberID}.
Is it just hidden or does it actually send in ${memberID} and not i.e.8107222059 with I expect it to do.

Is it allowed to say:

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

and reffering to the json request body looking like this:

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

and a testdatafile looking like this:

memberID,offerId
8107222059,000C297765971EE495BE0BA921A125F7
8107222052,000C297765971EE495BE0BA921A125F7





Pierre DAL-PRA

unread,
Nov 17, 2014, 10:08:22 AM11/17/14
to gat...@googlegroups.com
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

--
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.
For more options, visit https://groups.google.com/d/optout.

Magnus Jensen

unread,
Nov 17, 2014, 10:28:40 AM11/17/14
to gat...@googlegroups.com
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)

}


Pierre DAL-PRA

unread,
Nov 17, 2014, 10:31:01 AM11/17/14
to gat...@googlegroups.com
Short answer: yes.
Long answer: yes, as long as you do not add another .feed(csv("memberInfo.csv").random) between your execs.

Magnus Jensen

unread,
Nov 17, 2014, 11:28:50 AM11/17/14
to gat...@googlegroups.com
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

Pierre DAL-PRA

unread,
Nov 17, 2014, 11:57:52 AM11/17/14
to gat...@googlegroups.com
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.
Reply all
Reply to author
Forward
0 new messages