Parsing a Json response returned to Gatling

后端 未结 1 1201
南旧
南旧 2021-02-13 15:39

I am trying to parse a json response returned to gatling by the server.

My response from server is:

SessionAttribute(
  Session(
    GetServices,
    349         


        
相关标签:
1条回答
  • 2021-02-13 16:39

    It might be easiest to use a little bit more jsonPath to pull out the id you need, storing that in its own variable for later use. Remember that jsonPath is still a CheckBuilder, so you can't just access the result directly - it might have failed to match.

    Converting it to an Option[String] seems like a reasonable thing to do though.

    So your final few lines would become:

        ...
        .check(
          jsonPath("$.id").saveAs("myresponseId")
        )
      )
    ).exec(session => {
      val maybeId = session.get("myresponseId").asOption[String]
      println(maybeId.getOrElse("COULD NOT FIND ID"))
      session
    })
    
    0 讨论(0)
提交回复
热议问题