Skip to content

Instantly share code, notes, and snippets.

@bjpirt
Created May 25, 2012 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjpirt/2786805 to your computer and use it in GitHub Desktop.
Save bjpirt/2786805 to your computer and use it in GitHub Desktop.
A module to make sure selenium is already started
var http = require('http'),
spawn = require('child_process').spawn,
selenium;
var selenium_server = {
host: 'localhost',
port: 4444,
path: '/wd/hub/static/resource/hub.html',
method: 'GET'
};
exports.start = function(cb){
http.get(selenium_server, function(res) {
console.log("Selenium already running");
cb();
}).on('error', function(e) {
start_selenium(cb);
});
}
var start_selenium = function(cb){
console.log("Starting Selenium");
selenium = spawn('java', ['-jar', 'spec/support/selenium-server-standalone-2.20.0.jar']);
selenium.stdout.on('data', function(data){
data = data.toString();
if(!data.match(/INFO/)) console.log(data);
});
selenium.stderr.on('data', function(data){
data = data.toString();
if(data.match(/org\.openqa\.jetty\.util\.Container - Started org\.openqa\.jetty\.jetty\.Server@/)){
console.log("Selenium server started");
cb();
}
});
}
exports.stop = function(){
if(selenium !== undefined) selenium.kill();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment