1

Expected Response:

{"data":{
{"assignments":[{"locationId":"1186755","locationName":"X.11.11"},{"locationId":"1186756","locationName":"X.11.12"}]}}}

Response:

{"data":{
{"assignments":[{"locationId":"1186756","locationName":"X.11.12"},{"locationId":"1186755","locationName":"X.11.11"}]}}}

I saw a SO post stating to use karate.sort(response, x=>x.locationId), when i tried it's giving me empty response. Is there any simple way i can achieve do the comparison of whole response file irrespective of order?

Note: I even tried contains only, but it's failing the assertion.

1 Answers1

0

Just use contains deep: https://stackoverflow.com/a/64373344/143475

* def response = {"assignments":[{"locationId":"1186755","locationName":"X.11.11"},{"locationId":"1186756","locationName":"X.11.12"}]}}}
* match response contains deep {"assignments":[{"locationId":"1186756","locationName":"X.11.12"},{"locationId":"1186755","locationName":"X.11.11"}]}}}
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • I tried this ,so deep is matching even if one array element is not present - `* def response = {"assignments":[{"locationId":"1186755","locationName":"X.11.11"},{"locationId":"1186756","locationName":"X.11.12"}]}}}` `* match response contains deep {"assignments":[{"locationId":"1186756","locationName":"X.11.12"},{"locationId":"1186756","locationName":"X.11.12"}]}}}` – harshini reddy Sep 15 '22 at 19:23
  • @harshinireddy yes. now please read this: https://stackoverflow.com/a/72435914/143475 – Peter Thomas Sep 15 '22 at 19:54