Reputation: 41
for e.g.
* def products = [{"ProductCode":"a","UnitPrice":100.0},{ {"ProductCode":"b","UnitPrice":200.0}]
* def inventory = [{"ProductCode":"b","UnitPrice":200.0},{ {"ProductCode":"a","UnitPrice":100.0}]
* match products == inventory
This fails as the order of elements in the array are not matching. How can I tell karate to ignore the order?
Upvotes: 4
Views: 2360
Reputation: 58058
Please read the docs: https://github.com/intuit/karate#match-contains
* def products = [{"ProductCode":"a","UnitPrice":100.0},{"ProductCode":"b","UnitPrice":200.0}]
* def inventory = [{"ProductCode":"b","UnitPrice":200.0},{"ProductCode":"a","UnitPrice":100.0}]
* match products contains only inventory
Upvotes: 5
Reputation: 1
The match operation is smart because white-space does not matter, and the order of keys (or data elements) does not matter. Karate is even able to ignore fields you choose - which is very useful when you want to handle server-side dynamically generated fields such as UUID-s, time-stamps, security-tokens and the like.
The match syntax involves a double-equals sign '==' to represent a comparison (and not an assignment '=').
Upvotes: 0