1

I've got a request that returns a response node(itemCanBe) value in two possible ways, depending on the 'itemNum'. How do I assert this ? below attempt is not working

* match res..itemCanBe == null || res..itemCanBe[*] contains ['Colgate']

itemCanBe returning null

{
"itemDetails": {
    "1234": {
        "itemNum": "1234",
        "itemCanBe": null
    }
  }
}

itemCanBe returning array

{
"itemDetails": {
    "4567": {
        "itemNum": "4567",
        "itemCanBe": [
            "Colgate",
            "Sensodine"
        ]
    }
}

}

sam
  • 289
  • 7
  • 19

2 Answers2

2

See this thread for details: https://github.com/intuit/karate/issues/1202#issuecomment-653632397 This should be good enough to solve your problem.

Soumya
  • 21
  • 1
1

This will actually work:

* def temp = get[0] response..itemCanBe
* match temp == '##[]'

Also refer: https://stackoverflow.com/a/50350442/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248