英文:
AND condition in Karate
问题
[
{
"X": "shop",
"description": "ABC",
"Y": {
"Z": {
"T1": "1",
"T2": "2"
}
}
}]
现在需要在Karate中编写一个条件,如果(T1 == '1' && T2 == '2')则断言“X”=“shop”。如何在一行或简短的方式中实现这一目标?已尝试各种方法但未成功。
英文:
[
{
“X”: “shop”,
"description": “ABC”,
“Y”: {
“Z”: {
“T1”: “1”,
“T2”: “2”}
}
}]
Now need to write a condition in karate that if (T1 == ‘1’ && T2 == ‘2’) then assert that “X” = “shop”
How can we achieve this in a single line or in short way
Tried various methods but did not work
答案1
得分: 1
这确实是一个非常复杂的JSON,所以我会尝试"预处理"它以使其更简单。
以下是其中一种可能的解决方案之一。请使用提示来确定适合您的解决方案:
- def response = [{ X: 'shop', Y: { Z: { T1: '1', T2: '2' } } }]
- def data = response.map(x => ({ X: x.X, T1: x.Y.Z.T1, T2: x.Y.Z.T2 }))
- def good = data.filter(x => x.T1 == '1' && x.T2 == '2' && x.X == 'shop')
- match data == good
更多提示,请参考这里:https://stackoverflow.com/a/62567262/143475
英文:
This is certainly very complicated JSON, so I would try to "pre process" it to be simpler.
Here is one possible solution out of many. Please use the hints to arrive at what works for you:
* def response = [{ X: 'shop', Y: { Z: { T1: '1', T2: '2' } } }]
* def data = response.map(x => ({ X: x.X, T1: x.Y.Z.T1, T2: x.Y.Z.T2 }))
* def good = data.filter(x => x.T1 == '1' && x.T2 == '2' && x.X == 'shop')
* match data == good
Refer here for more hints: https://stackoverflow.com/a/62567262/143475
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论