1

I have 2 cases to verify

Case 1: Verify attribute lastName is present in response also need to check its value is null

{
 "name" : 
   {
      "firstName" : "Peter",
      "lastName"  : null
   }
}

Case 2: Verify attribute is not present in response

{
 "name" : 
   {
      "firstName" : "Peter"
   }
}

Here, I am trying to use karate.get('response.name.lastName') but in both case gives back null

Mandeep Rehal
  • 93
  • 2
  • 4
  • 11

1 Answers1

1

You should really read the documentation: https://github.com/intuit/karate#null-and-notpresent

* def response = { "name": { "firstName": "Peter", "lastName": null } }
* match response.name.lastName == '#null'

* def response = { "name": { "firstName": "Peter" } }
* match response.name.lastName == '#notpresent'
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • I have to write only one assertion to verify. If I use '#null', then in case its coming back with the value `"lastName" : "Thomas"` would fail. Also the case where attribute is not present in response would fail. – Mandeep Rehal Sep 23 '21 at 16:56
  • @MandeepRehal ok I think you want to handle both cases at the same time and your original question was not clear at all. I have marked this question as duplicate, and the linked q & a should answer all your questions. ask a new question if needed – Peter Thomas Sep 23 '21 at 17:07