首页 文章

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

提问于
浏览
1
  • URL 1 - >发布请求 - > JSON respose 1

  • URL 2 - >发布请求 - > JSON respose 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

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
    

相关问题