1 回答
TA贡献1816条经验 获得超4个赞
使用下面的代码片段来验证响应字段。
String responseXMLAsString = "<ValidationResponse> <errors> <error> <field>id</field> </error> <error> <field>amount</field> </error> </errors> </ValidationResponse>";
XmlPath xmlPath = new XmlPath(responseXMLAsString);
assertThat(xmlPath.get("ValidationResponse.errors.error.field"), contains("id","amount"));
或者
RestAssured.given()
.auth()
.preemptive()
.basic(theUsername, thePassword)
.contentType(theContentType)
.header("Accept",theContentType)
.body(theXMLBody)
.when()
.post(theURL)
.then()
.body("ValidationResponse.errors.error.field", contains("id","amount"));
其中contains()是hamcrest匹配器
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
添加回答
举报