我试图匹配响应中的特定变量,并尝试如下。但是我说KarateException Missing Property in path $['Odata']
时出现错误。我的问题是:我们如何进行修改,以免出现此错误?
功能
:And match response.@odata.context.a.b contains '<b>'
示例:
|b|
|b1 |
|b2 |
回复为
{
"@odata.context": "$metadata#Accounts",
"a": [
{
"c": 145729,
"b": "b1",
"d": "ON",
},
{
"c": 145729,
"b": "b2",
"d": "ON",
}
]
}
答案 0 :(得分:1)
我认为您对JSON的结构感到困惑。还要注意,当JSON键具有特殊字符时,您需要更改在路径表达式中使用它们的方式。您可以尝试将以下内容粘贴到新方案中,然后查看其工作情况:
* def response =
"""
{
"@odata.context": "$metadata#Accounts",
"a": [
{
"c": 145729,
"b": "b1",
"d": "ON",
},
{
"c": 145729,
"b": "b2",
"d": "ON",
}
]
}
"""
* match response['@odata.context'] == '$metadata#Accounts'
* match response.a[0].b == 'b1'
* match response.a[1].b == 'b2'