【问题标题】:Getting a problem with doWhile in Gatling while doing requests在执行请求时在 Gatling 中遇到 doWhile 问题
【发布时间】:2021-07-19 09:17:22
【问题描述】:

我正在尝试执行 doWhile,但我收到此编译错误:

特征循环中的方法 doWhile 缺少参数列表 只有在需要函数类型时,未应用的方法才会转换为函数。 您可以通过写doWhile _doWhile(_,_)(_) 而不是doWhile 来明确这种转换。

这是我的代码:

    builder
  .doWhile("${scrollId.exists()}") {
    exec(http(s"$title")
      .post(endpoint)
      .headers(headers)
      .body(ElFileBody(requestBodyFilePath))
      .check(jsonPath("$.scrollId").saveAs("scrollId"))
      .check(status.is(200)))
      .pause(1)
      //save value from response
      .exec(session => {
        .doIf(session("scrollId").asOption[String].isEmpty)
      val scrollId = session("scrollId").asOption[String].get
      session.set("scrollId", scrollId)
    })
  }
}

谢谢!

【问题讨论】:

    标签: java gatling


    【解决方案1】:

    doWhile 的正确语法是doWhile(condition) { chain },例如:

    builder
            .doWhile("${scrollId.exists()}") {
            exec(http(s"$title")
              .post(endpoint)
              .headers(headers)
              .body(ElFileBody(requestBodyFilePath))
              .check(jsonPath("$.scrollId").saveAs("scrollId"))
              .check(status.is(200)))
            .pause(1)
          //save value from response
              .exec(session => {
                val scrollId = session("scrollId").asOption[String].get
                session.set("scrollId", scrollId)
              })
       }
    

    【讨论】:

    • 谢谢!你是对的,你能告诉我如何在获取之前检查 session("scrollId").asOption[String] 的值吗?这个可以吗?我刚刚编辑了代码
    • @i 请在 StackOverFlow 上坚持 1 个问题 = 1 个帖子。在这里,请创建一个新的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-19
    • 1970-01-01
    • 1970-01-01
    • 2022-10-20
    • 2015-11-13
    • 2010-12-09
    • 1970-01-01
    相关资源
    最近更新 更多