这是示例代码
"xNotification": [
{
"code": "1234",
"text": "Invalid Data"
"yNotification": [
{
"code": "345",
"text": "Invalid Data"
}
]
}
]
}
yNotification数组有时仅在响应中退出,当存在时,我需要捕获代码值并将其放入变量中。我不想要断言只是存在时,我需要将其放入变量中。我是任何测试框架的新手。感谢您提供有关此问题的帮助。提前致谢。
请阅读文档的这一部分:https : //github.com/intuit/karate#conditional-logic
例:
* def expected = zone == 'zone1' ? { foo: '#string' } : { bar: '#number' }
* match response == expected
编辑:这是您的问题的完整解决方案:
* def response =
"""
{ "xNotification": [
{
"code": "1234",
"text": "Invalid Data",
"yNotification": [
{
"code": "345",
"text": "Invalid Data"
}
]
}
]
}
"""
* def code = karate.get('$.xNotification[0].yNotification[0].code')
* print code
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句