Home > database >  How to match a list of string with substring using contains in karate
How to match a list of string with substring using contains in karate

Time:09-23

* def response = ["-1302.3000","110992.2204","-3990.6580","-7678.6279","4964.0000","3415.6366"]
* def val = '-1302.3'
Then match response contains "#regex ."   val   ".*"

Error:- match failed: CONTAINS $ | not a string (LIST:STRING) ["-1302.3000","110992.2204","-3990.6580","-7678.6279","4964.0000","3415.6366"] '#regex .-1302.3.*'

CodePudding user response:

This works for me on the latest version of Karate (1.1.0)

* def response = ["-1302.3000","110992.2204","-3990.6580","-7678.6279","4964.0000","3415.6366"]
* def val = '-1302.3'
* match response contains "#regex "   val   ".*"

That said, see this suggestion below:

* def response = ["-1302.3000","110992.2204","-3990.6580","-7678.6279","4964.0000","3415.6366"]
* def numbers = response.map(x => x * 1)
* match numbers contains -1302.3

I leave it as a homework for you to understand how that works.

  • Related