Test if entire HTML response is equal to expected HTML

We have an API that returns HTML and want to write tests to validate that the HTML being returned is valid. We are not trying to parse the HTML, just do a direct comparison. Based on similar tests we created for JSON responses, we hoped something like this would work

const body = pm.response.text();
pm.test("check text body", function() {
pm.expect(body).to.eql(
{
<html>
<body>
My expected text here...
</body>
</html>
}
);
});

We get a syntax error: unexpected token ‘<’

@james.oleonard Welcome to the community :partying_face:

Here you can try to store the html as a variable and validate against it.

For example, store the expected html response in a global variable.

const body = pm.response.text();
pm.test("check text body", function() {
pm.expect(body).to.eql(pm.globals.get("html_resp"));
;
});
1 Like

Thanks but I need to set that global variable, which I tried doing in a pre-request script but then I run into the same problem there.

pm.globals.set("html_resp", "<html>
<body>
My expected text here...
</body>
</html>"
);

Error message is SyntaxError: Invalid or unexpected token