Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(e2e): Add workaround for selenium failure #2863

Merged
merged 1 commit into from
May 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
"test-all": "npm test && npm run test-e2e",
"test-unit": "node test/pretest.js && mocha",
"test-e2e": "node test/e2e/server.js --env default --config ./test/e2e/adminUI/nightwatch.json",
"test-e2e-bg": "node test/e2e/server.js --env default --selenium-in-background --config ./test/e2e/adminUI/nightwatch-no-process.json",
"test-e2e-saucelabs": "if [ -n \"$SAUCE_ACCESS_KEY\" ]; then node test/e2e/server.js --env saucelabs-travis --config ./test/e2e/adminUI/nightwatch.json; fi",
"lint": "eslint .",
"lint-fix": "eslint . --fix",
Expand Down
90 changes: 90 additions & 0 deletions test/e2e/adminUI/nightwatch-no-process.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"src_folders": [
"test/e2e/adminUI/tests"
],
"output_folder": "reports",
"custom_commands_path": "",
"custom_assertions_path": "",
"page_objects_path": "test/e2e/adminUI/pages",
"globals_path": "test/e2e/globals.js",
"selenium": {
"start_process": false,
"server_path": "test/e2e/bin/selenium-server-standalone-2.53.0.jar",
"log_path": "",
"host": "127.0.0.1",
"port": 4444,
"cli_args": {
"webdriver.chrome.driver": "",
"webdriver.ie.driver": ""
}
},
"test_settings": {
"default": {
"launch_url": "http://localhost",
"selenium_host": "127.0.0.1",
"selenium_port": 4444,
"silent": true,
"disable_colors": false,
"screenshots": {
"enabled": false,
"path": ""
},
"desiredCapabilities": {
"browserName": "firefox",
"javascriptEnabled": true,
"acceptSslCerts": true
},
"exclude": "test/e2e/adminUI/tests/group005Fields/commonFieldTestUtils.js"
},
"saucelabs-travis": {
"selenium_host": "ondemand.saucelabs.com",
"selenium_port": 80,
"username": "${SAUCE_USERNAME}",
"access_key": "${SAUCE_ACCESS_KEY}",
"use_ssl": false,
"silent": true,
"output": true,
"screenshots": {
"enabled": false,
"on_failure": true,
"path": ""
},
"desiredCapabilities": {
"name": "test-firefox",
"browserName": "firefox",
"tunnel-identifier": "${TRAVIS_JOB_NUMBER}"
},
"selenium": {
"start_process": false
}
},
"saucelabs-local": {
"selenium_host": "ondemand.saucelabs.com",
"selenium_port": 80,
"username": "${SAUCE_USERNAME}",
"access_key": "${SAUCE_ACCESS_KEY}",
"use_ssl": false,
"silent": true,
"output": true,
"screenshots": {
"enabled": false,
"on_failure": true,
"path": ""
},
"desiredCapabilities": {
"name": "test-firefox",
"browserName": "firefox"
},
"selenium": {
"start_process": false
}
},
"chrome": {
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true
}
}
}
}
49 changes: 48 additions & 1 deletion test/e2e/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ var request = require('superagent');
var moment = require('moment');
var mongoose = require('mongoose');
var Nightwatch = require('nightwatch/lib/index.js');
var child_process = require('child_process');
var path = require('path');

var dbName = '/e2e' + (process.env.KEYSTONEJS_PORT || 3000);
var mongoUri = 'mongodb://' + (process.env.KEYSTONEJS_HOST || 'localhost') + dbName;
Expand Down Expand Up @@ -95,6 +97,39 @@ function checkKeystoneReady (done, results) {
.end(done);
}

/*
On some machines, selenium fails with a timeout error when nightwatch tries to connect due to a
deadlock situation. The following is a temporary workaround that starts selenium without a pipe
from stdin until this issue is fixed in nightwatch:
https://github.com/nightwatchjs/nightwatch/issues/470
*/
function runSeleniumInBackground (done) {
var selenium = child_process.spawn('java',
[
'-jar',
path.join(__dirname, 'bin/selenium-server-standalone-2.53.0.jar')
],
{
stdio: ['ignore', 'pipe', 'pipe']
});
var running = false;

selenium.stderr.on('data', function (buffer)
{
var line = buffer.toString();
if(line.search(/Selenium Server is up and running/g) != -1) {
running = true;
done(null, selenium);
}
});

selenium.on('close', function (code) {
if(!running) {
done(new Error('Selenium exited with error code ' + code));
}
});
}

function runNightwatch () {
console.log([moment().format('HH:mm:ss:SSS')] + ' e2e: starting tests...');

Expand Down Expand Up @@ -144,7 +179,19 @@ function start() {
console.log([moment().format('HH:mm:ss:SSS')] + ' e2e: starting setup');

if (!err) {
runKeystone();
if (process.argv.indexOf('--selenium-in-background') == -1) {
runKeystone();
}
else {
runSeleniumInBackground(function (err, selenium) {
if(err) {
console.error('\nCould not start selenium in the background:\n\n');
console.error(err);
process.exit(3);
}
runKeystone();
});
}
} else {
console.error([moment().format('HH:mm:ss:SSS')] + ' e2e: failed to drop e2e test database: ' + err);
}
Expand Down