Created
August 30, 2018 21:51
-
-
Save CurtisHumphrey/d16af2006c7422accb711dac90a57414 to your computer and use it in GitHub Desktop.
nightwatch.js assertion for no browser logs
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 if the given element exists in the DOM. | |
* | |
* ``` | |
* this.demoTest = function (client) { | |
* browser.assert.noErrorLogs() | |
* } | |
* ``` | |
* | |
* @method noErrorLogs | |
* @param {boolean} [abortOnFailure] if it should continue or not if there is an error | |
* @param {string} [message] Optional log message to display in the output. If missing, one is displayed by default. | |
* @api assertions | |
*/ | |
const _ = require('lodash') | |
exports.assertion = function (abortOnFailure, msg) { | |
this.message = msg || 'Testing if browser had error logs' | |
this.expected = 'no errors' | |
this.abortOnFailure = abortOnFailure | |
this.pass = function (value) { | |
return _.isEmpty(value) | |
} | |
this.value = function (log_entries) { | |
const errors = [] | |
log_entries.forEach((log) => { | |
// if (log.level === '') | |
console.log(log) | |
errors.push(log.message) | |
}) | |
return errors.join(' | ') | |
} | |
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