我想比较两个嵌套的 json 响应,所以我使用“包含深度”。但是在比较时我想忽略一些字段(跳过这些字段的比较)。
示例:我想在比较下面给出的两个响应时忽略状态字段。
Scenario1:
* def response1 = { id: 1, name: 'John', address: { city: 'New York', state: 'NY' } }
* def response2 = { id: 1, name: 'John', address: { city: 'California', state: 'CA' } }
* match response1 contains deep response2
# Note: My requirement is tp show difference of city only in the karate report
Scenario2:
* def response1 = { id: 1, name: 'John', address: { city: 'New York', state: 'NY' } }
* def response2 = { id: 1, name: 'John', address: { city: 'New York', state: 'CA' } }
* match response1 contains deep response2
# Note: My requirement is to show no difference at all as the state node should be ignored in the karate report.
我不确定我到底应该在这里尝试什么来忽略该字段。请在这里帮忙。
tp 仅在空手道报告中显示城市差异
抱歉,空手道不是这样的。团队使用它进行像这样的模式验证,顺便说一句,这是“场景 2”的答案。
* match response contains deep { address: { city: '#string' } }
您所要求的可以通过代码完成。或者欢迎您为空手道贡献代码。
以下是重写场景 2 的方法:
* def response1 = { id: 1, name: 'John', address: { city: 'New York', state: 'NY' } }
* def response2 = { id: 1, name: 'John', address: { city: 'New York', state: 'CA' } }
* response2.address.state = '#string'
* match response1 == response2