1

I am trying to assert a list using match contains any, match each but it is not working.

  • def actualList = ["CABLE_MODEM","SET_TOP_BOX","SET_TOP_BOX","CABLE_MODEM","CBE"]
  • def expectedList = ["CABLE_CARD","SET_TOP_BOX","CABLE_MODEM","MTA","OTHER","IP_SET_TOP_BOX"]
  • match each actualList contains any expectedList

Basically, every value of the actualList should be any one of the expectedList value. But it is directly comparing the first value of the 2 lists. Kindly help me

1 Answers1

0

I'm not sure I understand the question. But sometimes these crazy assertions are best done in JS:

* def actualList = ["CABLE_MODEM","SET_TOP_BOX","SET_TOP_BOX","CABLE_MODEM","CBE"]
* def expectedList = ["CABLE_CARD","SET_TOP_BOX","CABLE_MODEM","MTA","OTHER","IP_SET_TOP_BOX"]
* def unexpected = actualList.filter(x => !expectedList.includes(x))
* match unexpected == []

Please take the help of a friend who knows JS if the above is not clear.

EDIT: for completeness, here's the "karate style" way to solve this. For more complex custom checks, karate.match() can be used.

* def valid = function(x){ return expectedList.includes(x) }
* match each actualList == '#? valid(_)'
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248