Saved response attribute value is not available in the subsequent request

16 views
Skip to first unread message

Chandra Sekhar Rudrakshala

unread,
Oct 14, 2016, 4:17:10 PM10/14/16
to Gatling User Group
I am trying to get productId from a json response and use it in the subsequent request. I am able to get its value within the session lambda but it is not available outside of it.  
   

 val postQueriesProductsHttp = http("PostQueriesProducts")
    .post("/v2/queries/products?include=products.basic-information")
    .body(StringBody(s"""{
    "queries": [{
      "id": "properties",
      "values": ["ABCDE"]
    },
    {
      "id": "start-date",
      "values": ["2016-11-03"]
    },
    {
      "id": "length-of-stay",
      "values": ["2"]
    },
    {
      "id": "quantity",
      "values": ["1"]
    },
    {
      "id": "number-in-party",
      "values": ["3"]
    },
    {
      "id": "rate-request-types",
      "values": [{
      "type": {
        "code": "standard"
      },
      "value": ""
    }]
    }]
  }"""))
    .check(status.is(200))

  val postCartsHttp = http("PostCarts")
    .post("/v2/carts")

  val postCarts = scenario("PostQueriesProducts")
    .exec(postQueriesProductsHttp.check(jsonPath("$..id").saveAs("productId")))
    .exec(session => {
      println(session("productId").asOption[String])
      var productId = session.get.attributes("productId").toString()
      println(productId)
      session
    })
    .exec(postCartsHttp
      .body(StringBody(s"""{
      "consumerId": "",
      "productId": "${productId}",
      "quantity": 1,
      "addOns": [{
      "id": "C2",
      "startDate": "2016-11-03",
      "endDate": "2016-11-04",
      "ordinal": 1
      }]
    }"""))
      .check(status.is(200)))
}

Chandra Sekhar Rudrakshala

unread,
Oct 14, 2016, 11:11:14 PM10/14/16
to Gatling User Group
Never mind. Figured it out.

val postCarts = scenario("PostQueriesProducts")
    .exec(session =>{
session.set("property",property).set("startDate",startDate).set("endDate",endDate)

})
.exec(postQueriesProductsHttp.check(jsonPath("$..id").saveAs("productId")))
  .exec(postCartsHttp
.body(StringBody("""{
  "consumerId": "",
"productId": "${productId}",
"quantity": 1,
"addOns": [{
"id": "C2",
  "startDate": "${startDate}",
"endDate": "${endDate}",
"ordinal": 1
}]
}"""))
.check(status.is(201)))
Reply all
Reply to author
Forward
0 new messages