I'm attempting to use a variable in the RHS of an JsonPath filter expression in a Karate test, similar to this:
* def name = 'A Name'
* def ids = $response[?(@.name == '#(name)')].id
If I use the literal string 'A Name' in the RHS of the expression it works as expected.
I've tried various ways to get the variable to evaluate:
'<name>', "#(name)", etc.
I suspect it is because I'm mixing JsonPath parsing with Karate parsing perhaps?
Read this first: https://github.com/intuit/karate#rules-for-embedded-expressions
And what you are looking for is this: https://github.com/intuit/karate#jsonpath-filters
* def ids = karate.jsonPath(response, "$.kittens[?(@.name=='" + name + "')].id")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With