空手道 API 框架 - 如何断言键的空值,如果该值为空则断言其他键不应存在
Karate API framework - How to assert the empty value of a key and if that value is empty then assert that some other key should not present
空手道中有什么方法可以检查是否有任何值作为空字符串出现,那么响应中的其他键不应出现 -
例如,如果您看到下面的示例 json 响应,其中一个 results[*].source.Descriptions[*].text
是空的,并且在同一节点上预览 results[*].source.preview
不存在
因此空手道中的任何直接解决方案都可以检查如果 Descriptions.text 是 ''
那么预览不应出现在该节点
{
"total": 10,
"count": 10,
"results": [
{
"id": "1",
"source": {
"type": "general",
"Description": [
{
"text": ""
}
]
}
},
{
"id": "2",
"source": {
"type": "general",
"preview": "Your name",
"Description": [
{
"text": "Your name is Karate"
}
]
}
}
]
}
给你。阅读文档以防有任何不清楚的地方:
* def isValid = function(x){ var desc = x.source.Description[0].text; return desc === '' ? !x.preview : true }
* match each response.results == '#? isValid(_)'
空手道中有什么方法可以检查是否有任何值作为空字符串出现,那么响应中的其他键不应出现 -
例如,如果您看到下面的示例 json 响应,其中一个 results[*].source.Descriptions[*].text
是空的,并且在同一节点上预览 results[*].source.preview
不存在
因此空手道中的任何直接解决方案都可以检查如果 Descriptions.text 是 ''
那么预览不应出现在该节点
{
"total": 10,
"count": 10,
"results": [
{
"id": "1",
"source": {
"type": "general",
"Description": [
{
"text": ""
}
]
}
},
{
"id": "2",
"source": {
"type": "general",
"preview": "Your name",
"Description": [
{
"text": "Your name is Karate"
}
]
}
}
]
}
给你。阅读文档以防有任何不清楚的地方:
* def isValid = function(x){ var desc = x.source.Description[0].text; return desc === '' ? !x.preview : true }
* match each response.results == '#? isValid(_)'