如何在空手道中验证JSON属性作为某个字符串返回?

发布于 2025-01-23 05:39:23 字数 237 浏览 1 评论 0原文

在空手道测试中,我想评估JSON响应中返回的属性是否为字符串类型。 以下是在做什么:

* def abc = response.results.abc
Then match abc == "#string?"

下面的响应是得到:

实际:'狮子',预期:'#string?',原因:没有评估“ true”

请让我知道我在哪里错误的。 谢谢。

In Karate tests, I'd like to evaluate whether an attribute returned in json response is of string type.
Below is what am doing:

* def abc = response.results.abc
Then match abc == "#string?"

Below is the response am getting:

actual: 'lion', expected: '#string?', reason: did not evaluate to 'true'

Please let me know where I am wrong.
Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

叹沉浮 2025-01-30 05:39:23

您正在纠正它: https://github.com/github.com/karateunabs/karate#schema-validation

* def response = { abc: 'foo' }
* match response.abc == '#string'

建议您一次匹配JSON对象,您的测试将更加清晰。

* match response == { abc: '#string' }

You are overcomplicating it: https://github.com/karatelabs/karate#schema-validation

* def response = { abc: 'foo' }
* match response.abc == '#string'

It is recommended you match JSON objects all at once, your tests will be more crisp.

* match response == { abc: '#string' }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文