我试图在 Karate 测试中使用 JsonPath 过滤器表达式的 RHS 中的变量,类似于:
* def name = 'A Name'
* def ids = $response[?(@.name == '#(name)')].id
如果我使用文字字符串 'A Name'
在表达式的 RHS 中,它按预期工作。
我尝试了多种方法来获取要评估的变量:
'<name>'
, "#(name)"
等
我怀疑这是因为我将 JsonPath 解析与 Karate 解析混合在一起了吗?
最佳答案
首先阅读:https://github.com/intuit/karate#rules-for-embedded-expressions
而您正在寻找的是:https://github.com/intuit/karate#jsonpath-filters
* def ids = karate.jsonPath(response, "$.kittens[?(@.name=='" + name + "')].id")
关于karate - 如何在 JsonPath 过滤器中使用变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57665464/