Search code examples
javascriptangularjstestingprotractorend-to-end

Fail Protractor on warnings


I looked through the protractor API and reference conf.js but I couldn't find any documentation on how to fail protractor on warnings or how to turn warnings into errors.

Is either of those possible?


Solution

  • There is nothing built-in in Protractor to treat warnings as errors.

    You can redefine the Protractor's log.warn() and throw an error instead of logging a warning:

    onPrepare: function () {
    
        var logger = require('protractor/lib/logger.js');
        logger.warn = function (message) {
            throw message;
        };
    },
    

    Works for me.


    Also, note that:

    WARNING - more than one element found for locator ... - the first result will be used

    This warning can easily be fixed by replacing the:

    element(...)
    

    with:

    element.all(...).first()