【问题标题】:How do i perform conditional check using Gatling我如何使用 Gatling 执行条件检查
【发布时间】:2018-03-09 18:04:39
【问题描述】:

我有这样的场景。

 private val feeder = Array(200, 404).map(e => Map("code" -> e)).random.circular

 private val search = scenario("search")
                          .feed(feeder)
                          .exec(http("search")
                          .get("/search/")
                          .headers(headers)
                          .check( if "${code}".equals(200) jsonPath("$.body").exists else jsonPath("$.exception").exists )

有没有办法可以实现这种条件检查。截至目前,观察到的行为是,"${code}".equals(200) 将始终返回 false。

【问题讨论】:

  • "${code}" 创建String,它永远不会等于整数。您可以尝试将"${code}".equals(200) 替换为code == 200 吗?
  • @RandallFlagg 我也试过了。也没有用。

标签: scala gatling scala-gatling


【解决方案1】:

您可以在jsonPath 中访问session 并手动从中提取code

.check(jsonPath(session => 
      if (session("code").as[Int].equals(200)) "$.body" 
      else "$.exception"
).exists)

【讨论】:

    【解决方案2】:

    根据documentation,有以下构造来实现这一点:

    // with a Gatling EL String condition that resolves a Boolean
    .checkIf("#{bool}") {
      jsonPath("$..foo")
    }
    // with a function
    .checkIf(session => session("key").as[String] == "executeCheck") {
      jsonPath("$..foo")
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-13
      • 2021-04-21
      • 2013-03-28
      • 2021-06-06
      • 2016-06-21
      • 2017-08-17
      • 1970-01-01
      相关资源
      最近更新 更多