0

When running my tests with CodeceptJS using the Protractor driver, the tests run successfully but the process does not exit, so I have to force-stop it everytime, and I also cannot run them on my CI server or it will always timeout. My codecept.conf.js:

const conf = require('../config/config');

exports.config = {
  tests: './e2e/**/*.spec.js',
  output: './e2e/reports',
  helpers: {
    Protractor: protractor.config,
    ProtractorHelper: {
      require: './e2e/protractor.helper.js'
    }
  },
  name: 'test',
  timeout: 10000,
  bootstrap: './e2e/before-launch.js',
  mocha: {
    reporterOptions: {
      reportDir: './reports'
    }
  }
};

My protractor.conf.js:

const conf = require('../config/config');

exports.config = {
  scriptsTimeout: 11000,
  browser: 'chrome',
  capabilities: {
    chromeOptions: {
      args: process.env.CI ? [
        '--no-sandbox',
        // See https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md
        '--headless',
        '--disable-gpu',
        // Without a remote debugging port, Google Chrome exits immediately.
        '--remote-debugging-port=9222',
        '--disable-web-security'
      ] : []
    }
  },
  directConnect: true,
  url: conf.e2e.baseUrl,
  noGlobals: true,
  rootElement: 'body'
};

And the before-launch.js which basically just serves up the website:

const conf = require('../config/config');

require('connect')().use(require('serve-static')(conf.e2e.paths.build)).listen(conf.e2e.servePort);

I am using:

  • CodeceptJS version: 1.4.1
  • NodeJS version: 10.1.0
  • Protractor version: 5.4.0
Guillaume
  • 2,912
  • 3
  • 35
  • 59

2 Answers2

0

You can create a gulp task

use gulp-protractor

var protractor = require("gulp-protractor").protractor;
var spawn = require('child_process').spawn; 
function runProtractorConfig() {
    gulp.src('./**/*-page.spec.js')
        .pipe(protractor({
            configFile: 'protractor.config.js'
        }))
        .on('error', function (e) {
            throw e;
        });
}

Now your process will exit automatically.

Bharath Kumar S
  • 1,410
  • 2
  • 10
  • 29
0

Turns out it was not exiting because of the connect which served up the website and kept listening at the end, so I changed the codecept config to:

bootstrap: 'run-server.js',
teardown: 'run-server.js',

and in run-server.js:

const http = require('http');
const connect = require('connect');

let app = connect();
app.use(require('serve-static')('public'));
let server = null;

module.exports = {
  bootstrap: function(done) {
    server = http.createServer(app);
    server.listen(3001);
    done();
  },
  teardown: function(done) {
    server.close();
    done();
  }
}

And now it exits just fine

Guillaume
  • 2,912
  • 3
  • 35
  • 59