Created
May 25, 2012 08:59
-
-
Save bjpirt/2786805 to your computer and use it in GitHub Desktop.
A module to make sure selenium is already started
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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