How to write custom failure messages for expect in Protractor/Jasmine reports

In Protractor ,We can override the error messaging in the Jasmine reporter by defining the custom matcher in the global scope and overrding the default message variable as follows:


beforeEach(function () {
    jasmine.addMatchers({
        toReport: function () {
            return {
                compare: function (actual, expected, msg) {
                    var result = {pass: actual == expected};
                    result.message = msg;
                    return result;
                }
            }
        }
    });
});
 
And it can be used in expect statements like below inside err function block:
 
 expect(false).toReport(true, "Unable to perform required operation because of " + err.message); 
 

Comments

Popular posts from this blog

Testing Webservice with SoapUI Having Windows Authentication

Data Driven Testing Using Selenium -WebDriver in Python

How to Re-run Failed Scenarios in Cucumber