我正在尝试在 Serenity 框架中使用 Rest Assured 来验证端点响应。我将一个 xml 正文发送到端点,并期望返回一个 JSON 响应,如下所示:
{"Entry ID" : "654123"}
Run Code Online (Sandbox Code Playgroud)
我想发送 XML 并在 JSON 响应中验证键“条目 ID”的值不为空或为空。问题是,密钥中有一个空格,我相信它会导致错误。这是我到目前为止所拥有的:
SerenityRest.given().contentType(ContentType.XML)
.body(xmlBody)
.when().accept(ContentType.JSON).post(endpoint)
.then().body("Entry ID", not(isEmptyOrNullString()))
.and().statusCode(200);
Run Code Online (Sandbox Code Playgroud)
这会产生错误:
java.lang.IllegalArgumentException: Invalid JSON expression:
Script1.groovy: 1: unable to resolve class Entry
@ line 1, column 33.
Entry ID
^
1 error
Run Code Online (Sandbox Code Playgroud)
我尝试以不同的方式包装“条目 ID”术语,但无济于事:
.body("'Entry ID'", not(isEmptyOrNullString()))
.body("''Entry ID''", not(isEmptyOrNullString()))
.body("\"Entry ID\"", not(isEmptyOrNullString()))
.body("['Entry ID']", not(isEmptyOrNullString()))
.body("$.['Entry ID']", not(isEmptyOrNullString()))
Run Code Online (Sandbox Code Playgroud)
是否可以在 Rest Assured 中获取包含空格的键的值?