djangofan
djangofan

Reputation: 29669

How can I do a Karate matcher for "any array item starts with" on a String array?

Let's say I have a "workflow result" equal to:

["START","Success : <0_4726310526.1228950033456.WEBSERVICES@random>","END"]

If I were to write a Karate matcher to verify that any item in that list "starts with the sub-string 'Success'", then how would I write the matcher?

This is what I tried and I can't get it to work:

* def starts_with = function(x){ return x.startsWith('Success') }
* match result_arr contains any ["# starts_with(_)"]

Couldn't find the answer in the documentation for Karate.

Upvotes: 2

Views: 499

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58058

Here you go:

* def response = ["START","Success : <0_4726310526.1228950033456.WEBSERVICES@random>","END"]
* def fun = function(x){ return x.startsWith('Success') }
* def temp = karate.filter(response, fun)
* assert temp.length > 0

Upvotes: 1

Related Questions