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(/"/g, '"'); // Replace " 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”?…’