0

Here is the sample json

{
  "result": [
    {
      "hostname": "CDGRPASEAAR001",
      "critical": 0,
      "minor": 1,
      "syslog": 0
    },
    {
      "hostname": "MUMBCHUDAAR001",
      "critical": 0,
      "minor": 0,
      "syslog": 0
    },
    {
      "hostname": "",
      "critical": 0,
      "minor": 1,
      "syslog": 0
    },

I am trying below:

And match actualResponse == {result[2].hostname: '##notnull'}

But I am getting this validation message:

reason: actual value has 4 more key(s) than expected

halfer
  • 19,824
  • 17
  • 99
  • 186
Cloudravi
  • 63
  • 1
  • 11

1 Answers1

1

I think this is what you were trying for:

* match response.result[2] contains { hostname: '##notnull' }

This would also work:

* match each response.result contains { hostname: '#string' }

So please go through the docs: https://github.com/karatelabs/karate#fuzzy-matching

If you are trying to find some count, then match is not what you want. You have to start doing transforms, like filter(). Refer: https://stackoverflow.com/a/74459339/143475 | https://stackoverflow.com/a/75425063/143475

For example:

* def names = response.result.filter(x => x.hostname !== '').map(x => x.hostname)
* match names == ['CDGRPASEAAR001', 'MUMBCHUDAAR001']
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248