谁能解释如何在空手道中获得两个响应之间的所有不匹配? [英] Can anyone explain how to get all the mismatch between two responses in karate?

查看:25
本文介绍了谁能解释如何在空手道中获得两个响应之间的所有不匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就像我有两个 JSON 如下,我想检查它们之间的不匹配

JSON 1:

{姓名:'约翰',联系人:'123',国家:'美国'}

Json 2:

{name:'vishal',联系人:'123',国家:'印度'}

现在它会返回我的名字和国家不匹配不仅仅是名字?

解决方案

否,不支持.我们认为这没有必要,因为在您的常规 CI 运行中,您只关心测试是通过还是失败,您会在日志中看到详细信息.

另请注意,如果您真的想要使用Scenario Outline,您可以模拟这一点:

Like if I have two JSON as below and I want to check the mismatch between those

Json 1:

{
  name:'john',
  contact:'123',
  country:'america'
}

Json 2:

{
  name:'vishal',
  contact:'123',
  country:'India'
}

Now it will return me with the mismatch between name and country not only the name?

解决方案

No this is not supported. We feel this is not needed, because in your regular CI runs you only care if the test passed or failed, and you see the details in the log.

Also note that you can simulate this if you really want using a Scenario Outline: https://stackoverflow.com/a/54108755/143475

Finally, if you care so much about this, kindly contribute code, this is open-source after all.

EDIT: you can easily do this by iterating over keys. Here is the code:

Feature:

Background:
* def json1 = { name: 'john', contact: '123', country: 'america' }
* def json2 = { name: 'vishal', contact: '123', country: 'India' }
* def keys = karate.keysOf(json1)
* def data = karate.mapWithKey(keys, 'key')

Scenario Outline: <key>
* match (json1[key]) == json2[key]

Examples:
| data |

And here is the report:

这篇关于谁能解释如何在空手道中获得两个响应之间的所有不匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆