How to signal test failure using browser.end()?
See original GitHub issueHey there,
I would love to see support for this. Sometimes, I want to prematurely end a test and output a FAIL signature to Jenkins. For example:
exports.command = function(callback) {
'use strict';
var jsdom = require('jsdom');
var self = this;
var url = this.globals.urls.dropWizard;
jsdom.env({
html: '<html><body></body></html>',
scripts: ['https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js'],
done: function pageCreated(err, window) {
let $ = window.jQuery;
$.ajax({
url: url,
method: 'GET',
beforeSend: function (request, settings) {
console.log('Request URL: %s', settings.url);
},
success: function (response) {
if (typeof callback === 'function') {
callback.call(self, response);
}
},
error: function (jqXHR) {
console.log('ERROR! \n%s', JSON.stringify(jqXHR));
self.end(); // SIGNAL FAIL HERE
}
});
}
});
// allows command to be chained
return this;
};
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
end | API Reference - Nightwatch.js
Remember always to call the .end() method when you want to close your test, in order for the Selenium session to be properly...
Read more >Tape "test exited without ending" error with asynchronous ...
Start browser 1 and navigate(Chrome) · One test on browser 1 (Chrome) · Close browser 1 (Chrome) · Start browser 2 and navigate...
Read more >How to Fix Flaky Tests - Semaphore CI
One efficient way to do this is to use a CI service such as Semaphore. By setting up a schedule on the main...
Read more >Browser Test Steps - Datadog Docs
To confirm your test ends in an expected state, you must end your browser tests with an assertion. Options for assertions in a...
Read more >React end-to-end testing with Jest and Puppeteer
To show how E2E testing works in React, we'll write tests for a functional React app and see what happens when the tests...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

For anyone else as confused as I was about where the assert.fail is being defined… Nightwatch extends the Node.JS assert module. see http://nightwatchjs.org/api/#assertions
This can also be achieved using something like:
I’m closing this since for now I think this solves the problem.