Skip to content

Commit

Permalink
Merge pull request #10 from Waxolunist/selenium-install-optional
Browse files Browse the repository at this point in the history
Add new option skipSeleniumInstall to skip the installation process.
  • Loading branch information
dfreedm committed Sep 1, 2015
2 parents 4d4fed5 + 435f02c commit 9fded0a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 18 deletions.
21 changes: 15 additions & 6 deletions lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ module.exports = function(wct, pluginOptions) {
// kick in if someone has specified browsers via another plugin.
wct.hookLate('configure', function(done) {
pluginOptions.seleniumPort = pluginOptions.seleniumPort || parseInt(process.env.SELENIUM_PORT);

pluginOptions.skipSeleniumInstall = pluginOptions.skipSeleniumInstall || false;

var names = browsers.normalize(pluginOptions.browsers);
if (names.length > 0) {
// We support comma separated browser identifiers for convenience.
Expand Down Expand Up @@ -71,11 +72,19 @@ module.exports = function(wct, pluginOptions) {
if (error) return done(error);
selenium.checkSeleniumEnvironment(function(error) {
if (error) return done(error);
selenium.startSeleniumServer(wct, function(error, port) {
if (error) return done(error);
updatePort(eachCapabilities, port);
done();
});
if(pluginOptions.skipSeleniumInstall) {
selenium.startSeleniumServer(wct, function(error, port) {
if (error) return done(error);
updatePort(eachCapabilities, port);
done();
});
} else {
selenium.installAndStartSeleniumServer(wct, function(error, port) {
if (error) return done(error);
updatePort(eachCapabilities, port);
done();
});
}
});
});

Expand Down
45 changes: 33 additions & 12 deletions lib/selenium.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ function checkSeleniumEnvironment(done) {

function startSeleniumServer(wct, done) {
wct.emit('log:info', 'Starting Selenium server for local browsers');
checkSeleniumEnvironment(function(error) {
checkSeleniumEnvironment(seleniumStart(wct, done, true));
}

function installAndStartSeleniumServer(wct, done) {
wct.emit('log:info', 'Installing and starting Selenium server for local browsers');
checkSeleniumEnvironment(seleniumStart(wct, done, false));
}

function seleniumStart(wct, done, skipinstall) {
return function(error) {
if (error) return done(error);
freeport(function(error, port) {
if (error) return done(error);
Expand Down Expand Up @@ -63,13 +72,18 @@ function startSeleniumServer(wct, done) {
server.stderr.on('data', onOutput);
},
};

// Ensure that we have the latest version downloaded.
selenium.install({version: '2.47.1', logger: onOutput}, function(error) {
if (error) {
log.forEach(function(line) { wct.emit('log:info', line) });
return done(error);
}

function install() {
selenium.install({version: '2.47.1', logger: onOutput}, function(error) {
if (error) {
log.forEach(function(line) { wct.emit('log:info', line) });
return done(error);
}
start();
});
}

function start() {
selenium.start(config, function(error) {
if (error) {
log.forEach(function(line) { wct.emit('log:info', line) });
Expand All @@ -78,12 +92,19 @@ function startSeleniumServer(wct, done) {
wct.emit('log:info', 'Selenium server running on port', chalk.yellow(port));
done(null, port);
});
});
}

if(skipinstall) {
start();
} else {
install();
}
});
});
};
}

module.exports = {
checkSeleniumEnvironment: checkSeleniumEnvironment,
startSeleniumServer: startSeleniumServer,
checkSeleniumEnvironment: checkSeleniumEnvironment,
startSeleniumServer: startSeleniumServer,
installAndStartSeleniumServer: installAndStartSeleniumServer
};

0 comments on commit 9fded0a

Please sign in to comment.