Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nightwatch with Chromedriver does not exit after assertions

I have an issue whereby Nightwatch is not exiting after all the assertions have passed. The execution seems to freeze and never exits despite the chrome driver being closed.

The versions are as follows:

chromedriver (headless): 2.41.0
selenium-server: 3.14.0
nightwatch: 1.0.9

The firefox driver is working correctly.

The contents of runner.js are below:

// 1. start the dev server using production config
process.env.NODE_ENV = 'testing';

const webpack = require('webpack');
const DevServer = require('webpack-dev-server');

const webpackConfig = require('../../build/webpack.prod.conf');
const devConfigPromise = require('../../build/webpack.dev.conf');

let server;

devConfigPromise.then((devConfig) => {
  const devServerOptions = devConfig.devServer;
  const compiler = webpack(webpackConfig);
  server = new DevServer(compiler, devServerOptions);
  const port = devServerOptions.port;
  const host = devServerOptions.host;
  return server.listen(port, host);
})
  .then(() => {
  // 2. run the nightwatch test suite against it
  // to run in additional browsers:
  //    1. add an entry in test/e2e/nightwatch.conf.js under "test_settings"
  //    2. add it to the --env flag below
  // or override the environment flag, for example: `npm run e2e -- --env chrome,firefox`
  // For more information on Nightwatch's config file, see
  // http://nightwatchjs.org/guide#settings-file
    let opts = process.argv.slice(2);
    if (opts.indexOf('--config') === -1) {
      opts = opts.concat(['--config', 'test/e2e/nightwatch.conf.js']);
    }
    if (opts.indexOf('--env') === -1) {
      opts = opts.concat(['--env', 'chrome']);
    }

    const spawn = require('cross-spawn');
    const runner = spawn('./node_modules/.bin/nightwatch', opts, { stdio: 'inherit' });

    runner.on('exit', (code) => {
      server.close();
      process.exit(code);
    });

    runner.on('error', (err) => {
      console.log(`About to exit with code: ${err}`);
      server.close();
      throw err;
    });
  });

The contents of the nightwatch.conf.js is below:

require('babel-register');
const config = require('../../config');

// http://nightwatchjs.org/gettingstarted#settings-file
module.exports = {
  src_folders: ['test/e2e/specs'],
  output_folder: 'test/e2e/reports',
  custom_assertions_path: ['test/e2e/custom-assertions'],

  selenium: {
    start_process: true,
    server_path: require('selenium-server').path,
    host: '127.0.0.1',
    port: 4444,
    cli_args: {
      'webdrive.gecko.driver': require('geckodriver').path,
      'webdriver.chrome.driver': require('chromedriver').path,
    },
  },
  test_settings: {
    default: {
      selenium_port: 5555,
      selenium_host: 'localhost',
      silent: true,
      globals: {
        devServerURL: `http://localhost:${process.env.PORT || config.dev.port}`,
        serverUrl: '[server url]',
      },
    },

    chrome: {
      desiredCapabilities: {
        browserName: 'chrome',
        javascriptEnabled: true,
        acceptSslCerts: true,
        chromeOptions: {
          args: [
            '--headless', '--no-sandbox',
          ],
        },
      },
    },

    firefox: {
      desiredCapabilities: {
        browserName: 'firefox',
        javascriptEnabled: true,
        acceptSslCerts: true,
        'moz:firefoxOptions': {
          args: [
            '-headless',
          ],
        },
      },
    },
  },
};

Any help would be greatly appreciated as I haven't been able to find a solution so far.

like image 311
user3523340 Avatar asked Aug 21 '18 13:08

user3523340


1 Answers

First, make sure you're calling browser.end() as the last step of each test.

Second, Nightwatch 1.0+ is still in beta. I'd try version 0.9.21, that's what most people are still using. File a bug against version 1.09 if 0.9.21 works.

like image 153
pschroeder89 Avatar answered Oct 26 '22 23:10

pschroeder89