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


URL 1 -->
  1. post request --> JSON repose 1
  2. URL 2 -->
  3. 发布请求 --> JSON 回复 2

如何比较响应 1 和响应 2

?响应 2 将具有额外的属性,因此不能直接使用匹配命令

响应1 { 姓名 : 您好, 国家 : ABCD} 响应2 { 名称 : 你好, 国家: ABCD, 州: xyz}

只想比较名称和国家/地区属性,不想硬编码比较,例如 匹配 response1.name == response2.name

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

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

喜欢呼叫读取("比较.js"(响应1 响应2

是的。请阅读文档: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

最新更新