Gatling. Fetch data from response for next requests

风格不统一 提交于 2020-01-03 02:31:23

问题


I need to fetch optional data from a JSON response to build next requests. I use check(jsonPath("...rooms[0].id").exists.saveAs("...roomId")) but if the user has no rooms, the result is interpreted by .check() as an error (e.g. request count 4 (OK=3 KO=1))

object Users {
  val execute = exec(http("Users"))
    .get("/api/user?userIdentifier=${userId}")
    // if user has no rooms, the check results in an error (KO) 
    .check(jsonPath("$..user.rooms[0].id").exists.saveAs("roomId"))
    .pause(1)
}

object Room {
  val execute = exec(http("Room"))
    .get("/api/room?id=${roomId}")
    .pause(1)
}

val readOnlyScenario = scenario("Read only scenario") {
  .feed(userIdsdata)
  .exec(Users.execute,
    doIf(session => session.contains("roomId")) {
      Room.execute
    }
  )
}

How can I fetch optional data from a JSON response and save it in the session (if present) without .check() failing when the data is not present?


回答1:


exists must be replaced by optional

.check(jsonPath("$..user.rooms[0].id").optional.saveAs("roomId"))


来源:https://stackoverflow.com/questions/40717357/gatling-fetch-data-from-response-for-next-requests

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!