Created
January 15, 2020 10:46
-
-
Save Fishbowler/3b1c8c2ee2e8a6e1c93691d173827cda to your computer and use it in GitHub Desktop.
Nightwatch custom assertion for No Console Errors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Checks that the browser console log currently contains zero errors | |
* | |
* ``` | |
* this.demoTest = function (client) { | |
* browser.assert.noConsoleErrors("Checking console for errors"); | |
* }; | |
* | |
* this.demoTest = function (client) { | |
* browser.assert.noConsoleErrors("reports/console.log","Checking console for errors"); | |
* }; | |
* ``` | |
* | |
* @method noConsoleErrors | |
* @param {string} logfile Optional logfile to write the console log to | |
* @param {string} msg Optional log message to display in the output. If missing, one is displayed by default. | |
* @api assertions | |
* | |
*/ | |
var util = require('util'); | |
exports.assertion = function(logfile,msg) { | |
this.timeout=0 | |
this.formatMessage = function() { | |
const message = msg || 'Checking console for errors. '; | |
return { | |
message, | |
args: [] | |
} | |
}; | |
this.expected = '0 console errors'; | |
this.actual = function(passed){ | |
return passed ? 'No console errors' : 'Found console errors' | |
} | |
this.evaluate = function(value){ | |
if(value == 0) return true; | |
return false; | |
} | |
this.value = function(result){ | |
var errors = []; | |
if(result && (result instanceof Array)){ | |
errors = result.filter(function(log) { | |
return ((log.level == "SEVERE") && (!log.message.includes('favicon'))); | |
}); | |
} | |
return errors.length; | |
} | |
this.command = function(callback){ | |
return this.api.getLog('browser', callback); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment