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

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

问题描述

就像我有以下两个JSON一样,我想检查两者之间的不匹配

杰森1:

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

杰森2:

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

现在,它不仅会给我带来名称和国家/地区之间的不匹配,还会给我带来不便?

解决方案

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

还请注意,如果您确实想使用Scenario Outline,则可以模拟此情况: https://stackoverflow.com/a/54108755/143475

最后,如果您对此非常在意,请贡献代码,毕竟这是开源的.

您可以通过遍历键轻松地完成此操作.这是代码:

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 |

这是报告:

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天全站免登陆