如何使用空手道工具比较2个JSON对象 [英] How to compare 2 JSON objects using Karate tool
问题描述
- URL 1->发布请求-> JSON重新放置1
- URL 2->发布请求-> JSON重新放置2
如何比较响应1和响应2?
How to compare response 1 and response 2 ?
响应2将具有额外的属性,因此不能直接使用匹配命令
response 2 will have extra attributes so cannot directly use match command
Response1 {名称:你好,国家/地区:ABCD} Response2 {名称:您好,国家/地区:ABCD,状态:xyz}
Response1 { name : hello, country : ABCD} Response2 { name : hello, country: ABCD, state: xyz}
只想比较名称和国家/地区属性,不想像这样硬比较 匹配response1.name == response2.name
Want to compare only name and country attributes and don't want to hardcode comparison like match response1.name == response2.name
将来可能会添加额外的属性,并且不想经常修改脚本
In future extra attributes may be added and don't want to modify the script frequently
或
无论如何,都需要将空手道中的两个响应都传递给JavaScript函数并进行比较
Is there anyway to pass both the responses to JavaScript function from karate and perform comparison
类似于通话读取('comparison.js')response1 response2
Like call read ('comparison.js') response1 response2
推荐答案
是.请阅读文档: https://github.com/intuit/karate#match-contains
* def response1 = { foo: 'bar', hello: 'world' }
* def response2 = { foo: 'bar', hello: 'world', extra: 'blah' }
* match response2 contains response1
这篇关于如何使用空手道工具比较2个JSON对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!