如何在JsonPath过滤器中使用变量 [英] How to use a variable in JsonPath filter

查看:497
本文介绍了如何在JsonPath过滤器中使用变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在空手道测试中的JsonPath过滤器表达式的RHS中使用一个变量,

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

如果我在表达式的RHS中使用文字字符串'A Name',它将按预期工作.

If I use the literal string 'A Name' in the RHS of the expression it works as expected.

我尝试了各种方法来获取变量以进行评估: '<name>'"#(name)"

I've tried various ways to get the variable to evaluate: '<name>', "#(name)", etc.

我怀疑是因为我正在混合JsonPath解析和空手道解析?

I suspect it is because I'm mixing JsonPath parsing with Karate parsing perhaps?

推荐答案

请先阅读以下内容:您正在寻找的是: https://github.com/intuit/karate#jsonpath-filters

* def ids = karate.jsonPath(response, "$.kittens[?(@.name=='" + name + "')].id")

这篇关于如何在JsonPath过滤器中使用变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆