karate - 空手道 - 匹配两个复杂的洗牌 json
问题描述
下面的问题与此非常相似:空手道 - 验证存储在不同文件中的 json 响应我经历了建议的包含快捷方式,但无法找出答案。
我需要比较两个 json 文件,但使用 contains 关键字。为什么只包含?因为在某些情况下,我只需要匹配 json 文件中的一些选定字段。以下是示例和代码。
Json 文件 1:Test.Json
{
"webServiceDetail":{
"feature":{
"featureCd":"ABCD",
"imaginaryInd":"100.0",
"extraInd1":"someRandomValue1"
},
"includefeatureList":[
{
"featureCd":"PQRS",
"featureName":"Checking SecondAddOn Service",
"extraInd1":"someRandomValue1",
"extraInd2":"someRandomValue1"
},
{
"featureCd":"XYZ",
"featureName":"Checking AddOn Service",
"imaginaryInd":"50.0"
}
]
}
}
Json 文件 2:Test1.json
{
"webServiceSummary":{
"service":{
"serviceCd":"ABCD"
},
"includeServicesList":[
{
"serviceCd":"XYZ",
"serviceDescription": "Checking AddOn Service"
},
{
"serviceDescription":"Checking SecondAddOn Service",
"serviceCd":"PQRS",
"randon":"FGDD"
}
]
}
}
我的代码:
* def Test = read('classpath:PP1/data/test.json')
* def Test1 = read('classpath:PP1/data/Test1.json')
* def feature = Test.webServiceDetail.feature
* set expected.webServiceSummary.service
| path | value |
| serviceCd | feature.featureCd |
* def mapper = function(x){ return { serviceCd: x.featureCd, serviceDescription: x.featureName} }
* def expectedList = karate.map(Test.webServiceDetail.includefeatureList, mapper)
* set expected.webServiceSummary.includeServicesList = '#(^*expectedList)'
* match Test1.webServiceSummary.includeServicesList == expected.webServiceSummary.includeServicesList
现在,上面的代码完美运行,我也得到了成功响应。但我担心的是我在contains any
这里匹配。我应该用contains
关键字验证。因为我需要确保所有参数expected.webServiceSummary.includeServicesList
都存在于Test1.webServiceSummary.includeServicesList
;不是其中的任何一个或一些。我尝试使用#(^expectedList)
-- for contains; 但没有成功。我知道这一系列问题看起来很傻,但我无法弄清楚行为!
解决方案
这将始终检查 . 中contains only
所有数组元素的值expectedList
。
'#(^^expectedList)'
推荐阅读
- r - R Flexdashboard 单个选项卡上的多个绘图
- c# - Unity 2018 - NPC 在射程内顺利转向面对玩家
- java - 如何显示java程序的依赖关系图?
- excel-formula - 从小数列表中返回一个整数
- angular - 错误:未捕获(承诺):错误:无法匹配任何路由。URL 段:“站点通知”
- swift - 更快的 Twitter 设置
- ios - 选择图片时 UIImagePickerController 冻结
- react-native - 如何从普通导航器堆栈中打开模式?
- reactjs - Centos 6 的 Electron/nw.js 的 Web 运行时替代品?
- java - 遍历数组