在比较空手道中的两个响应时,我们如何忽略一些嵌套字段,我使用“包含深度”进行比较

问题描述 投票:0回答:1

我想比较两个嵌套的 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.

我不确定我到底应该在这里尝试什么来忽略该字段。请在这里帮忙。

karate contains
1个回答
0
投票

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
© www.soinside.com 2019 - 2024. All rights reserved.