Reputation: 47
* def a2Company = get a2Names $..companyName //["TEST ABC"]
* def a1Company1 = get a1Names $..companyName1 //["TEST"]
* def a1Company2 = get a1Names $..companyName2 //["ABC"]
* def a1Company = a1Company1 + a1Company2 // ["TEST"]["ABC"]
* match a2Company contains a1Company1 // this fails
I am comparing two APIs and for one of the value in api 2 is a combination of 2 values from api1
The above doesnt seem to work I tried with javascript with concat but same issue
Any help is appreciated!
Upvotes: 0
Views: 124
Reputation: 5224
The match x contains y
works on the types of x
and y
. If these two are of type array
than contains means that the array x
contains all values of the array y
.
Example:
Scenario: Contains with arrays
* def x = ["test", "abc"]
* def y = ["test"]
* def z = ["abc"]
* match x contains y
* match x contains z
If x
and y
are strings, then contains means that the string y
can be found in x
, x
contains y
. Does this make sense?
Example:
Scenario: Contains with string
* def x = "test abc"
* def y = "test"
* def z = "abc"
* match x contains y
* match x contains z
You try to mix these things. You have arrays, but you want to apply string contains on array values. That doesn't work, because karate doesn't know, that you want to apply the contains an the values of a single valued array.
A workaround could be:
Scenario: Test array value contains string
* def x = ["test abc"]
* def y = ["test"]
* match x[0] contains y[0]
Does this help you?
Upvotes: 1