问题
- URL 1 --> post request --> JSON respose 1
- 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