【发布时间】:2021-03-12 17:04:14
【问题描述】:
在一个测试用例中,我使用以下响应执行调用:
[
{
"ourID": "770050010000000010",
"date": "2019-03-07",
"otherValue": null
},
{
"ourID": "770050010000000020",
"date": "2019-03-07",
"otherValue": null
}
]
测试由 Serenity 执行,我使用 RestAssured 执行调用:
Response response = RestAssuredApiHelper.baseRestCall(headers, baseUrl, path)
.body(requestBody)
.post();
assertThat(response.getBody().jsonPath().get("$.[?(@.ourID=='770050010000000010')].date"), contains("2019-03-07"));
断言不起作用,可能是因为 RestAssured 使用 Gpath 而不是 JsonPath,但在我读过的所有文档中,都有一些可行的方法示例。 我在这里错过了什么?
我得到的错误是:
java.lang.IllegalArgumentException: Invalid JSON expression:
Script1.groovy: 1: unexpected token: [ @ line 1, column 29.
$.[?(@.meteringPointEANID=='770050010000000010')].energySource
^
1 error
【问题讨论】:
-
接受以下任何对您有帮助的答案,以便对其他人有所帮助
标签: java rest-assured serenity-bdd rest-assured-jsonpath