空手道框架中是否有 if 功能?
Is there a if functionality in Karate framework?
这里是示例代码
"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
这里是示例代码
"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