0

I am parsing a response for all the names object and it returns an array

* def getName = response.source[*].name

And print getName

The api response looks like

[print] [
"Map of USA",
"Global map",
"Check map of RSA"
]

I want to match whether the getName[*] starts with 'map' or contains 'map' by ignoring the upper case also. I am able to do the contains match using -

* def getLowerCase = karate.lowerCase(getName)
* match each getLowerCase[*] contains 'map'

But not sure how to put the startsWith condition also in the same line. Can anyone help me out with the logic. Thanks in advance !

vdrulerz
  • 264
  • 3
  • 13

1 Answers1

2

Here you go:

* def names = ['map foo', 'foo map', 'f map oo']

* def hasMap = function(x){ return x.startsWith('map') || x.toLowerCase().contains('map') }
* match each names == '#? hasMap(_)'
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248