Skip to content

Instantly share code, notes, and snippets.

@CurtisHumphrey
Created August 30, 2018 21:51
Show Gist options
  • Save CurtisHumphrey/d16af2006c7422accb711dac90a57414 to your computer and use it in GitHub Desktop.
Save CurtisHumphrey/d16af2006c7422accb711dac90a57414 to your computer and use it in GitHub Desktop.
nightwatch.js assertion for no browser logs
/**
* 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