Skip to content

Commit

Permalink
Provide a way to customise the port Selenium starts on
Browse files Browse the repository at this point in the history
Fixes daaku#7
  • Loading branch information
mmetcalfe-pulsemining committed Jan 13, 2015
1 parent d754ca5 commit 39f969d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/selenium-launcher.js
Expand Up @@ -52,9 +52,8 @@ function download(url, outfile, expectedSha, cb) {
})
}

function run(cb) {
freeport(function(er, port) {
if (er) throw er;
function run(cb, port) {
function runOnPort(cb, port) {
console.log('Starting Selenium ' + version + ' on port ' + port);
console.log('Filename: ' + outfile);
var child = spawn('java', [
Expand All @@ -73,7 +72,16 @@ function run(cb) {
}
})
child.on('exit', badExit)
})
}

if (typeof port === 'undefined') {
freeport(function (er, port) {
if (er) throw er;
runOnPort(cb, port)
})
} else {
runOnPort(cb, port)
}
}

function FakeProcess(port) {
Expand All @@ -86,14 +94,14 @@ FakeProcess.prototype.kill = function() {
this.emit('exit');
}

module.exports = function(cb) {
module.exports = function(cb, port) {
if (process.env.SELENIUM_LAUNCHER_PORT) {
return process.nextTick(
cb.bind(null, null, new FakeProcess(process.env.SELENIUM_LAUNCHER_PORT)))
}

download(url, outfile, expectedSha, function(er) {
if (er) return cb(er)
run(cb)
run(cb, port)
})
}
9 changes: 9 additions & 0 deletions test/sanity.js
Expand Up @@ -40,4 +40,13 @@ describe("sanity", function(){
})
});

it('should get the server port from the optional parameter', function(done) {
seleniumLauncher(function(er, selenium) {
if (er) return done(er);
assert.equal(selenium.port, 4444);
selenium.on('exit', function() { done() })
selenium.kill()
}, 4444)
});

});

0 comments on commit 39f969d

Please sign in to comment.