Hassan ALAMI
Hassan ALAMI

Reputation: 347

Postman tests - Assert response is a valid XML

I would like to verify that the response of my webservice is a valid xml. I know that it can be simply done for json responses using the following snippet:

    pm.response.to.be.json;

What about XML ?

pm.test("The body of the response is a valid XML", function () {
    pm.response.to.be.withBody;
    pm.response.to.be.xml; // ❓
});

Upvotes: 1

Views: 2038

Answers (1)

Divyang Desai
Divyang Desai

Reputation: 7864

There would be multiple ways, here is the one.

Convert XML body to a JSON object using in built function xml2Json. If the function returns a value, response valid, otherwise, it is invalid.

pm.test("The body of the response is a valid XML", function () {
     pm.expect(xml2Json(responseBody)).to.exist;
});

Upvotes: 4

Related Questions