1

I am trying to compare responses from two service call(for Migration project) using Karate. Is it possible to exclude or ignore some keys while comparing whole response at one go for following cases:

1)There are few elements in response where the values is different(marked in bold). 2)There are few elements which is not present in one response but present in other(marked in bold).

Service 1 response -

{
  "userKey": "string",
  "enabled": true,
  "locked": true,
  "profile": {},
  "roles": [
    {
      "roleKey": 3,
      "name": "Role",
      **"links": []**
    }
  ],
  "links": [
    {
      "rel": "self",
      **"href": "https://starhub1.com"**
    },
    {
      "rel": "self",
      **"href": "https://singtel1.com"**
    }
  ]
}

Service 2 response -

{
  "userKey": "string",
  "enabled": true,
  "locked": true,
  "profile": {},
  "roles": [
    {
      "roleKey": 3,
      "name": "Role"
    }
  ],
  "links": [
    {
      "rel": "self",
      **"href": "https://starhub22.com"**
    },
    {
      "rel": "self",
      **"href": "https://singtel22.com"**
    }`enter code here`
  ]
}
Abhinaw
  • 23
  • 2

1 Answers1

0

Yes Karate is pretty good at this. Just do a transform on one payload before comparison.

Please see this answer for details: https://stackoverflow.com/a/53120851/143475

For your specifc example maybe all you need to do is change one "side" to #string and then do the comparison.

* def response1 = { foo: 'hello' }
* def response2 = { foo: 'world' }
* response2.foo = '#string'
* match response1 == response2
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248