Custom Error messages

Hi,

I have done a Google, but cannot find a specific answer to my question. I am using PM.TEST to do includes / to.be.true etx.

As the includes scans all text on the page the error message is not clear (as it provides all text before the lookup term).

Is there any way to add a custom message onto:

pm.test("Confirm Expected User Details are on Page : Title", function(){

    pm.expect(pm.response.text()).to.include("Mr");
    // On Fail (error"Mr was not found in the source returned"
});

or

pm.test("Confirm Expected User Details are on Page : Married / Unmarried", function(){

    const responseText = pm.response.text();

    const hasItemDetails = (responseText.includes('Married') || responseText.includes('UnMarried'));    

    pm.expect(hasItemDetails).to.be.true;
   // Error("Marriage Information not present in source")

});

Not the information does not come back in JSON but HTML.

Looking to replace // with proper code

Thanks

Hey @JBird20 ,

Welcome to the community :clap:

You can review this document. The assertion message should be in the second parameter.

   pm.test("Confirm Expected User Details are on Page : Married / Unmarried", function(){

    const responseText = pm.response.text();

    const hasItemDetails = (responseText.includes('Married') || responseText.includes('UnMarried'));    

    pm.expect(hasItemDetails, "Marriage Information not present in source").to.be.true;

});
1 Like