How to use a variable in JsonPath filter

旧城冷巷雨未停 提交于 2019-12-11 06:17:07

问题


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?


回答1:


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")


来源:https://stackoverflow.com/questions/57665464/how-to-use-a-variable-in-jsonpath-filter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!