RestAssured XmlPath array



我使用RestAssured来测试一些SOAP服务。我想验证XML响应的一部分,但是对于数组,我遇到了问题。我想验证一下,有3个代码"响应中值为0的字段。

XML响应:

<soap:Envelope xmlns:soap="...">
<soap:Body>
<Response xmlns="...">
<Result xmlns="">
<code>0</code>
</Result>
<Result xmlns="">
<code>0</code>
</Result>
<Result xmlns="">
<code>0</code>
</Result>
</Response>
</soap:Body>
</soap:Envelope>

我试过了,但是我得到的是[000]而不是[0,0,0]:

response.getBody().xmlPath().get("code.list()");

我也尝试过使用Xpath,它可以工作,但是它不检查"code">字段的数量

response.then().body(hasXPath("//code[text()=0]"));

但是当我想检查计数时,它失败了。AssertionError: 1 expectation failed.)

response.then().body(hasXPath("count(//code[text()=0])=3"));

REST - assured框架主要支持测试REST服务。您可以在Internet上找到很多示例,但它们并不总是适用于您唯一的SOAP响应体。

根据我的经验,我建议您注意一下Karate,因为它内置了对SOAP的支持,并且还使XML操作更容易。