6

我有一个问题,即在所有断言都通过后 Nightwatch 没有退出。尽管 chrome 驱动程序已关闭,但执行似乎冻结并且永远不会退出。

版本如下:

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

Firefox 驱动程序工作正常。

runner.js 的内容如下:

// 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;
    });
  });

nightwatch.conf.js 的内容如下:

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',
          ],
        },
      },
    },
  },
};

任何帮助将不胜感激,因为到目前为止我还没有找到解决方案。

4

1 回答 1

1

首先,确保您调用 browser.end() 作为每个测试的最后一步。

其次,Nightwatch 1.0+ 仍处于测试阶段。我会尝试 0.9.21 版本,这是大多数人仍在使用的版本。如果 0.9.21 有效,请提交针对 1.09 版的错误。

于 2018-08-25T18:06:08.150 回答