【问题标题】:Check value extracted with JSONPath and compare with regex using Gatling检查使用 JSONPath 提取的值并使用 Gatling 与正则表达式进行比较
【发布时间】:2019-05-15 11:32:24
【问题描述】:

有没有办法在加特林做这样的事情:

scenario("Check UUID with regex")
      .exec(http("Get UUID")
      .get("http://myapp/api/v1/goal/a24e210c-0fc1-44a0-a5ca-9bd5d8d71916")        
      .check(jsonPath("$.id").is(regex("[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}")))

基本上,我想对检查 JSONPath 构造中返回的内容应用正则表达式比较。

和平!

附:我知道我能做到: .check(regex("\"id\": \"[0-9a-fA-F]{8}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{12}\"").exists)

【问题讨论】:

    标签: regex scala gatling scala-gatling


    【解决方案1】:

    没有什么和你描述的完全一样,但你可以使用转换来伪造它

    .check(jsonPath("$.id")
        .find
        .transform(id => "[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}".r
                     .findFirstMatchIn(id) match {
                        case Some(value) => true
                        case None => false                     
                      }
         ).is(true)
    

    但如果直接正则表达式检查有效......我会去的

    【讨论】:

    • 有 validate 方法允许用户传入任意代码。 def validate(opName: String, validator: (Option[X], Session) => Validation[Option[X]])
    猜你喜欢
    • 2016-06-21
    • 2016-05-08
    • 1970-01-01
    • 1970-01-01
    • 2022-12-12
    • 2021-03-14
    • 1970-01-01
    • 2012-01-03
    • 1970-01-01
    相关资源
    最近更新 更多