jsonpath响应断言问题
Assertion Issue of jsonpath response
我正在编写 api 使用空手道的 bdd 方法测试自动化代码。
断言部分让我很难受。我的回复如下所示,当我调用该路径 $.data.subscribers[0].products
时,这给了我在 http://jsonpath.herokuapp.com/ 网站上检查过的空数组。但是,当我 运行 我的小黄瓜空手道功能然后它给我的响应为 null,它仍然给我错误断言。它说实际:
null, expected: 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'
只需使用 JsonPath 通配符(..
或 *
)。请注意,当您使用通配符时 - 结果将 始终 是一个 JSON 数组。这是您的解决方案:
* match response.data..subscribers[0].products[0] == []
我正在编写 api 使用空手道的 bdd 方法测试自动化代码。
断言部分让我很难受。我的回复如下所示,当我调用该路径 $.data.subscribers[0].products
时,这给了我在 http://jsonpath.herokuapp.com/ 网站上检查过的空数组。但是,当我 运行 我的小黄瓜空手道功能然后它给我的响应为 null,它仍然给我错误断言。它说实际:
null, expected: 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'
只需使用 JsonPath 通配符(..
或 *
)。请注意,当您使用通配符时 - 结果将 始终 是一个 JSON 数组。这是您的解决方案:
* match response.data..subscribers[0].products[0] == []