【问题标题】:Assertion Issue of jsonpath responsejsonpath响应的断言问题
【发布时间】:2019-04-10 06:50:53
【问题描述】:

我正在使用空手道的 bdd 方法编写 api 测试自动化代码。
断言部分让我很难受。我的回复如下所示,当我调用该路径$.data.subscribers[0].products 时,这给了我空空数组,正如我通过http://jsonpath.herokuapp.com/ 网站检查的那样。但是,当我运行我的小黄瓜空手道功能时,它给我的响应为空,它仍然给我错误断言。它说实际:

null,预期:null...

我看不到任何错误,我该如何解决这个问题?是bug还是有什么方法可以处理?

我的回答:

{
  "meta": {
    "return_code": 0,
    "message": "success"
  },
  "data": {
    "sbs": [
      {
        "sbs_id": 32432432,
        "dt": "OTT",
        "pt": []
      },
      {
        "sbs_id": 455654445,
        "dt": "IPTV",
        "pt": []
      }
    ]
  }
}

我写的JsonPath:

$.data.sbs[0].pt[0]

空手道的断言:

com.intuit.karate.exception.KarateException: base-tvpp-cases.feature:316 
- path: $[0], actual: null, expected: null, reason: actual json-path does 
not exist

Gherkin-Karate- 我在功能文件中编写的代码: 我在下面都试过了

And match response.data.subscribers[0].products[0] == null
And match response.data.subscribers[0].products[0] == '#null'

【问题讨论】:

    标签: karate gherkin


    【解决方案1】:

    只需使用 JsonPath 通配符(..*)。请注意,当您使用通配符时 - 结果将始终为 JSON 数组。这是您的解决方案:

    * match response.data..subscribers[0].products[0] == []
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-30
      • 1970-01-01
      • 1970-01-01
      • 2019-01-15
      相关资源
      最近更新 更多