How to compare 2 JSON objects using Karate tool

二次信任 提交于 2019-12-24 08:46:52

问题


  1. URL 1 --> post request --> JSON respose 1
  2. URL 2 --> post request --> JSON respose 2

How to compare response 1 and response 2 ?

response 2 will have extra attributes so cannot directly use match command

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

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

Or

Is there anyway to pass both the responses to JavaScript function from karate and perform comparison

Like call read ('comparison.js') response1 response2


回答1:


Yes. Please read the documentation: 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


来源:https://stackoverflow.com/questions/52245848/how-to-compare-2-json-objects-using-karate-tool

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!