question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to signal test failure using browser.end()?

See original GitHub issue

Hey 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:closed
  • Created 7 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
SgtPookicommented, Jul 14, 2017

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

4reactions
beatfactorcommented, Aug 15, 2016

This can also be achieved using something like:

'Demo test Google' : function (client) {
    client
      .url('http://google.com', function(result) {
        // second empty string argument is the expected value
        client.assert.fail(JSON.stringify(errorResponse), '', 'More details about the error');
      })
    ...
};

I’m closing this since for now I think this solves the problem.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found