jsonpath响应的断言问题 [英] Assertion Issue of jsonpath response
问题描述
我正在用Karate的bdd方法编写api测试自动化代码.
断言部分使我很难受.我的回答如下所示,当我调用该路径$.data.subscribers[0].products
时,这给了我空空数组,这是由 http检查的://jsonpath.herokuapp.com/网站.但是,当我运行小黄瓜空手道功能时,它给我的响应为null,它仍然给我错误声明.它说的是实际的:
I'm writing api test automated codes with bdd method by Karate.
Assertion part pushes me hard. My response is like below, and when I called that path $.data.subscribers[0].products
this gives me empty-null array as I checked by http://jsonpath.herokuapp.com/ website. However, when I run my gherkin Karate feature then It gave me the response as null, It still gives me error assertion. It says actual:
空,预期:空...
null, expected: null...
我看不到任何错误,该如何解决?是bug还是有任何方法可以解决?
I couldn't see any error, how can I fix this? Is it a bug or Is there any method to handle it?
我的答复:
{
"meta": {
"return_code": 0,
"message": "success"
},
"data": {
"sbs": [
{
"sbs_id": 32432432,
"dt": "OTT",
"pt": []
},
{
"sbs_id": 455654445,
"dt": "IPTV",
"pt": []
}
]
}
}
我写的JsonPath:
JsonPath that I wrote:
$.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- code that I wrote in feature file: I tried both below
And match response.data.subscribers[0].products[0] == null
And match response.data.subscribers[0].products[0] == '#null'
推荐答案
只需使用JsonPath通配符(..
或*
).请注意,当您使用通配符时-结果总是 为JSON数组.这是您的解决方案:
Just use a JsonPath wildcard (..
or *
). Note that when you use a wildcard - the result will always be a JSON array. Here is your solution:
* match response.data..subscribers[0].products[0] == []
这篇关于jsonpath响应的断言问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!