如何断言 JSON 中存在的响应值?

how to put assertion on a response value present in JSON?

我有一个这样的测试用例,我在其中验证总行数 - 我参考了下面的 page 并尝试了这个解决方案,但似乎它不起作用。我想检查我的 noOfRows 是否大于 2。

这是我得到的打印响应

总行数[ { “1”:27 } ]

    * def noOfRows = result
    * print 'Total number of rows ',result
    * assert noOfRows == { "1": '#? _ > 2' }

如果result是一个数组,你可以这样做:

* def result = [1, 2, 3]
* assert result.length > 2

readRows returns 与空手道无关,所以如果需要,请与了解 Java 的人合作:

另外,您似乎使用的是旧版空手道,因此请升级。如果仍然卡住,请按照以下过程操作:https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue