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

How to compare 2 JSON objects using Karate tool

  1. URL 1 --> post 请求 --> JSON 响应 1
  2. URL 2 --> post 请求 --> JSON 响应 2

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

response 2 会有额外的属性所以不能直接使用 match 命令

Response1 { 姓名:你好,国家:ABCD} Response2 { 姓名:你好,国家:ABCD,州:xyz}

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

以后可能会增加额外的属性,不想经常修改脚本

有没有办法将空手道的响应传递给 JavaScript 函数并进行比较

点赞调用阅读 ('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