如何使用空手道工具比较2个JSON对象

问题描述 投票:1回答:1
  1. URL 1 - >发布请求 - > JSON响应1
  2. URL 2 - >发布请求 - > JSON响应2

如何比较响应1和响应2?

响应2将具有额外属性,因此无法直接使用match命令

Response1 {name:hello,country:ABCD} Response2 {name:hello,country:ABCD,state:xyz}

想要仅比较名称和国家/地区属性,并且不希望硬匹配比较,例如匹配response1.name == response2.name

将来可能会添加额外的属性,并且不希望经常修改脚本

要么

无论如何都要从空手道传递对JavaScript函数的响应并执行比较

像调用read('comparison.js')response1 response2

karate
1个回答
1
投票

是。请阅读文档: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
© www.soinside.com 2019 - 2024. All rights reserved.