繁体   English   中英

Gatling - Scala:如何重复请求,直到 API 响应中存在某个响应变量?

[英]Gatling - Scala : How to repeat a request until a certain response variable exists in the API response?

Gatling - Scala:如何重复请求,直到 API 响应中存在某个响应变量?

这是求一个cursor分页API的响应时间的请求

.exec(http("APITests:Cursor Pagination")
  .get("/testapi")
  .queryParam("sortField", "ID")
  .queryParam("limit", limitCount)
  .queryParam("cursor", "#{CursorID}")
  .check(jsonPath("$.nextCursor")).exists
 .check(status.is(200))
)

我必须重复请求执行直到.check(jsonPath("$.nextCursor")).exists = False

请提供建议和帮助

我在下面尝试以错误结尾:

 doWhile(session => session(".check(jsonPath(\"$.nextCursor\").exists").as[Boolean]) {
    exec(http("APITests:Cursor Pagination")
      .get("/testapi")
      .queryParam("sortField", "ID")
      .queryParam("limit", limitCount)
      .queryParam("cursor", "#{CursorID}")
      .check(status.is(200))
      .check(jsonPath("$.nextCursor").exists
    ))
  }

但我最终遇到错误: jsonPath($.nextCursor).find.exists, found nothing

使用contains ,但你必须将nextCursor保存到Session

    doWhile(session => !session.contains("nextCursor")) {
      exec(http("...")
        .get("/")
        .check(jsonPath("$.nextCursor").saveAs("nextCursor"))
      )
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM