How to display mismatches in Two XML Responses Comparison?

How to display mismatches in Two XML Responses Comparison?

Endpoint: TempConvert Web Service

Request A:
Body:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
   <FahrenheitToCelsius xmlns="https://www.w3schools.com/xml/">
     <Fahrenheit>100</Fahrenheit>
   </FahrenheitToCelsius>
  </soap:Body>
</soap:Envelope>

Test Script:
// Fixed JSONError by removing JSON.stringify and replacing " with "

let jsonData = pm.response.text();

jsonData = jsonData.replace(/&quot;/g, '"'); // Replace &quot; with "

pm.collectionVariables.set("responseA", jsonData);

Request B:
Body:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
   <FahrenheitToCelsius xmlns="https://www.w3schools.com/xml/">
     <Fahrenheit>1000</Fahrenheit>
   </FahrenheitToCelsius>
  </soap:Body>
</soap:Envelope>

Test Script:

let responseA = pm.collectionVariables.get("responseA");
let responseB = pm.response.text();

pm.test("Compare responses", function () {
    pm.expect(responseA).to.equal(responseB);
});

Expected Result:
Test Script should show what are the mismatches occurs

Actual result:
Showing Error alone without mismatches details.
Error:
failed
Compare responses | AssertionError: expected undefined to equal ‘<?xml version=“1.0” encoding=“utf-8”?…’

ResponseA is coming back as defined, so it doesn’t look like its pulling in the info from your collection variable. So at the moment, its comparing your response text with undefined.

Doing a DIFF with native JavaScript is complex, and Postman doesn’t have any additional libraries in the sandbox to help do you do this.

It will do a simple compare, and yes, it will be hard (or impossible) to read if there are multiple differences.

This may be a test where you have an initial error so you know there is a difference which means that you then have to perform some manual testing (by coping and pasting the two responses into an external tool or website to perform the DIFF fully).

1 Like

Is it possible to delete some tags in stored variable response?