Postman 测试 - 断言响应有效 XML
Postman tests - Assert response is a valid XML
我想验证我的网络服务的响应是否有效 xml。
我知道可以使用以下代码段简单地为 json 响应完成:
pm.response.to.be.json;
那XML呢?
pm.test("The body of the response is a valid XML", function () {
pm.response.to.be.withBody;
pm.response.to.be.xml; // ❓
});
有多种方法,这里是一种。
使用内置函数 xml2Json
将 XML 主体转换为 JSON 对象。如果函数returns有值,响应有效,否则,无效。
pm.test("The body of the response is a valid XML", function () {
pm.expect(xml2Json(responseBody)).to.exist;
});
我想验证我的网络服务的响应是否有效 xml。 我知道可以使用以下代码段简单地为 json 响应完成:
pm.response.to.be.json;
那XML呢?
pm.test("The body of the response is a valid XML", function () {
pm.response.to.be.withBody;
pm.response.to.be.xml; // ❓
});
有多种方法,这里是一种。
使用内置函数 xml2Json
将 XML 主体转换为 JSON 对象。如果函数returns有值,响应有效,否则,无效。
pm.test("The body of the response is a valid XML", function () {
pm.expect(xml2Json(responseBody)).to.exist;
});