selenium-standalone
Advanced tools
Comparing version 3.0.3 to 3.1.0
@@ -0,1 +1,12 @@ | ||
# 3.1.0 (2015-01-17) | ||
* add `opts.logger` to `install()`, defaults to `noop` | ||
* add `opts.progressCb` to `install(opts)`, now you can receive progress information | ||
* log more info when installing: source, destination | ||
* show progress when installing | ||
* check for pathsexistence before starting and error accordingly | ||
* add `opts.spawnCb` to `start()`, now you can receive the spawned process asap | ||
* more tests | ||
* readme tweaks | ||
# 3.0.3 (2015-01-10) | ||
@@ -2,0 +13,0 @@ |
@@ -11,4 +11,4 @@ module.exports = computePaths; | ||
ie: path.join(basePath, 'iedriver', opts.drivers.ie.version + '-' + opts.drivers.ie.arch + '-IEDriverServer.exe'), | ||
selenium: path.join(basePath, 'selenium-server', opts.version + '-server.jar') | ||
selenium: path.join(basePath, 'selenium-server', opts.seleniumVersion + '-server.jar') | ||
}; | ||
} |
module.exports = install; | ||
var async = require('async'); | ||
var debug = require('debug')('selenium-standalone:lib/install'); | ||
var fs = require('fs'); | ||
@@ -10,8 +9,14 @@ var merge = require('lodash').merge; | ||
var request = require('request'); | ||
var util = require('util'); | ||
var computeDownloadUrls = require('./compute-download-urls'); | ||
var computePaths = require('./compute-paths'); | ||
var defaultConfig = require('./default-config'); | ||
var noop = require('./noop'); | ||
function install(opts, cb) { | ||
var total = 0; | ||
var progress = 0; | ||
var startedRequests = 0; | ||
var expectedRequests = 3; | ||
if (typeof opts === 'function') { | ||
@@ -22,2 +27,4 @@ cb = opts; | ||
var logger = opts.logger || noop; | ||
if (!opts.version) { | ||
@@ -29,171 +36,165 @@ opts.version = defaultConfig.version; | ||
logger('----------'); | ||
logger('selenium-standalone installation starting'); | ||
logger('----------'); | ||
logger(''); | ||
var paths = computePaths({ | ||
version: opts.version, | ||
seleniumVersion: opts.version, | ||
drivers: opts.drivers | ||
}); | ||
var urls = computeDownloadUrls({ | ||
seleniumVersion: opts.version, | ||
drivers: opts.drivers, | ||
}); | ||
if (process.platform !== 'win32') { | ||
delete paths.ie; | ||
delete urls.ie; | ||
expectedRequests -= 1; | ||
} | ||
logInstallSummary(logger, paths, urls); | ||
async.series([ | ||
createDirs.bind(null, paths), | ||
download.bind(null, { | ||
version: opts.version, | ||
drivers: opts.drivers, | ||
urls: urls, | ||
paths: paths | ||
}), | ||
chmodChromeDr.bind(null, paths.chrome) | ||
chmodChromeDr.bind(null, paths.chrome), | ||
asyncLogEnd.bind(null, logger), | ||
], cb); | ||
} | ||
function createDirs(paths, cb) { | ||
async.eachSeries([paths.selenium, paths.chrome, paths.ie].map(basePath), mkdirp, cb); | ||
} | ||
function download(opts, cb) { | ||
var steps = [ | ||
installSelenium.bind(null, { | ||
from: opts.urls.selenium, | ||
to: opts.paths.selenium | ||
}), | ||
installChromeDr.bind(null, { | ||
from: opts.urls.chrome, | ||
to: opts.paths.chrome | ||
}) | ||
]; | ||
function basePath(fullPath) { | ||
return path.dirname(fullPath); | ||
} | ||
if (process.platform === 'win32') { | ||
steps.push(installIeDr.bind(null, { | ||
from: opts.urls.ie, | ||
to: opts.paths.ie | ||
})); | ||
} | ||
function download(opts, cb) { | ||
var steps = [ | ||
installChromeDr.bind(null, { | ||
path: opts.paths.chrome, | ||
driver: opts.drivers.chrome | ||
}), | ||
installSelenium.bind(null, { | ||
path: opts.paths.selenium, | ||
version: opts.version | ||
}) | ||
]; | ||
async.parallel(steps, cb); | ||
} | ||
if (process.platform === 'win32') { | ||
steps.push(installIeDr.bind(null, { | ||
path: opts.paths.ie, | ||
seleniumVersion: opts.version, | ||
driver: opts.drivers.ie | ||
})); | ||
function installSelenium(opts, cb) { | ||
getDownloadStream(opts.from, function(err, stream) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
stream | ||
.pipe(fs.createWriteStream(opts.to)) | ||
.once('error', cb.bind(null, new Error('Could not write to ' + opts.to))) | ||
.once('finish', cb); | ||
}); | ||
} | ||
async.parallel(steps, cb); | ||
} | ||
function installChromeDr(opts, cb) { | ||
installZippedFile(opts.from, opts.to, cb); | ||
} | ||
function installSelenium(opts, cb) { | ||
var seleniumStandaloneUrl = | ||
'http://selenium-release.storage.googleapis.com/%s/selenium-server-standalone-%s.jar'; | ||
function installIeDr(opts, cb) { | ||
installZippedFile(opts.from, opts.to, cb); | ||
} | ||
var dl = util.format(seleniumStandaloneUrl, | ||
opts.version.slice(0, opts.version.lastIndexOf('.')), | ||
opts.version); | ||
function installZippedFile(from, to, cb) { | ||
var unzip = require('unzip'); | ||
getDownloadStream(dl, function(err, stream) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
getDownloadStream(from, function(err, stream) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
stream | ||
.pipe(fs.createWriteStream(opts.path)) | ||
.once('error', cb.bind(null, new Error('Could not write to ' + opts.path))) | ||
.once('finish', cb); | ||
}); | ||
} | ||
stream | ||
.pipe(unzip.Parse()) | ||
.once('entry', function(file) { | ||
file | ||
.pipe(fs.createWriteStream(to)) | ||
.once('error', cb.bind(null, new Error('Could not write to ' + to))) | ||
.once('finish', cb); | ||
}) | ||
.once('error', cb.bind(null, new Error('Could not unzip ' + from))); | ||
}); | ||
} | ||
function chmodChromeDr(where, cb) { | ||
debug('chmod+x chromedriver'); | ||
fs.chmod(where, '0755', cb); | ||
} | ||
function getDownloadStream(downloadUrl, cb) { | ||
var r = request(downloadUrl) | ||
.on('response', function(res) { | ||
startedRequests += 1; | ||
function installChromeDr(opts, cb) { | ||
var chromedriverUrl = 'http://chromedriver.storage.googleapis.com/%s/chromedriver_%s.zip'; | ||
var platform = getChromeDriverPlatform(opts.driver.arch); | ||
if (res.statusCode !== 200) { | ||
return cb(new Error('Could not download ' + downloadUrl)); | ||
} | ||
if (platform instanceof Error) { | ||
return cb(platform); | ||
} | ||
res.on('data', function(chunk) { | ||
progress += chunk.length; | ||
updateProgressPercentage(chunk.length); | ||
}); | ||
var downloadUrl = util.format(chromedriverUrl, opts.driver.version, platform); | ||
total += parseInt(res.headers['content-length'], 10); | ||
installZippedFile(opts.path, downloadUrl, cb); | ||
} | ||
cb(null, res); | ||
}) | ||
.once('error', cb.bind(null, new Error('Could not download ' + downloadUrl))); | ||
function installIeDr(opts, cb) { | ||
var ieDriverUrl = 'http://selenium-release.storage.googleapis.com/%s/IEDriverServer_%s_%s.zip'; | ||
var platform = getIeDriverPlatform(opts.driver.arch); | ||
if (platform instanceof Error) { | ||
return cb(platform); | ||
// initiate request | ||
r.end(); | ||
} | ||
var downloadUrl = util.format( | ||
ieDriverUrl, | ||
opts.seleniumVersion.slice(0, opts.driver.version.lastIndexOf('.')), | ||
platform, | ||
opts.driver.version | ||
); | ||
installZippedFile(opts.path, downloadUrl, cb); | ||
function updateProgressPercentage(chunk) { | ||
if (expectedRequests === startedRequests) { | ||
opts.progressCb(total, progress, chunk); | ||
} | ||
} | ||
} | ||
function installZippedFile(to, url, cb) { | ||
getDownloadStream(url, function(err, stream) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
var unzip = require('unzip'); | ||
debug('Unzipping ' + url); | ||
stream | ||
.pipe(unzip.Parse()) | ||
.once('entry', function(file) { | ||
file | ||
.pipe(fs.createWriteStream(to)) | ||
.once('error', cb.bind(null, new Error('Could not write to ' + to))) | ||
.once('finish', cb); | ||
}) | ||
.once('error', cb.bind(null, new Error('Could not unzip ' + url))); | ||
function asyncLogEnd(logger, cb) { | ||
setImmediate(function() { | ||
logger(''); | ||
logger(''); | ||
logger('-----'); | ||
logger('selenium-standalone installation finished'); | ||
logger('-----'); | ||
cb(); | ||
}); | ||
} | ||
function getDownloadStream(downloadUrl, cb) { | ||
var r = request(downloadUrl) | ||
.on('response', function(res) { | ||
debug('Downloading ' + downloadUrl, res.statusCode); | ||
function createDirs(paths, cb) { | ||
async.eachSeries([paths.selenium, paths.chrome, paths.ie].map(basePath), mkdirp, cb); | ||
} | ||
if (res.statusCode !== 200) { | ||
return cb(new Error('Could not download ' + downloadUrl)); | ||
} | ||
cb(null, res); | ||
}) | ||
.once('error', cb.bind(null, new Error('Could not download ' + downloadUrl))); | ||
// initiate request | ||
r.end(); | ||
function basePath(fullPath) { | ||
return path.dirname(fullPath); | ||
} | ||
function getChromeDriverPlatform(asked) { | ||
var platform; | ||
if (process.platform === 'linux') { | ||
platform = 'linux' + ( asked === 'x64' ? '64' : '32' ); | ||
} else if (process.platform === 'darwin') { | ||
platform = 'mac32'; | ||
} else if (process.platform === 'win32') { | ||
platform = 'win32'; | ||
} else { | ||
return new Error('Platform not supported'); | ||
} | ||
return platform; | ||
function chmodChromeDr(where, cb) { | ||
fs.chmod(where, '0755', cb); | ||
} | ||
function getIeDriverPlatform(asked) { | ||
var platform; | ||
function logInstallSummary(logger, paths, urls) { | ||
['selenium', 'chrome', 'ie'].forEach(function log(name) { | ||
if (!paths[name]) { | ||
return; | ||
} | ||
if (asked === 'ia32') { | ||
platform = 'Win32'; | ||
} else if (asked === 'x64') { | ||
platform = 'x64'; | ||
} else { | ||
return new Error('Architecture not supported'); | ||
} | ||
logger('---'); | ||
logger(name + ' install:'); | ||
logger('from: ' + urls[name]); | ||
logger('to: ' + paths[name]); | ||
}); | ||
return platform; | ||
// logger(''); | ||
} |
@@ -6,5 +6,7 @@ module.exports = start; | ||
var checkPathsExistence = require('./check-paths-existence'); | ||
var checkStarted = require('./check-started'); | ||
var computePaths = require('./compute-paths'); | ||
var defaultConfig = require('./default-config'); | ||
var noop = require('./noop'); | ||
@@ -25,6 +27,10 @@ function start(opts, cb) { | ||
if (!opts.spawnCb) { | ||
opts.spawnCb = noop; | ||
} | ||
opts.drivers = merge(defaultConfig.drivers, opts.drivers || {}); | ||
var paths = computePaths({ | ||
version: opts.version, | ||
seleniumVersion: opts.version, | ||
drivers: opts.drivers | ||
@@ -45,2 +51,4 @@ }); | ||
args.push('-Dwebdriver.ie.driver=' + paths.ie); | ||
} else { | ||
delete paths.ie; | ||
} | ||
@@ -50,5 +58,3 @@ | ||
var selenium = spawn('java', args, opts.spawnOptions); | ||
checkStarted(args, function started(err) { | ||
checkPathsExistence(paths, function(err) { | ||
if (err) { | ||
@@ -59,4 +65,23 @@ cb(err); | ||
cb(null, selenium); | ||
var selenium = spawn('java', args, opts.spawnOptions); | ||
opts.spawnCb(selenium); | ||
selenium.on('exit', errorIfNeverStarted); | ||
checkStarted(args, function started(err) { | ||
selenium.removeListener('exit', errorIfNeverStarted); | ||
if (err) { | ||
cb(err); | ||
return; | ||
} | ||
cb(null, selenium); | ||
}); | ||
function errorIfNeverStarted() { | ||
cb(new Error('Selenium exited before it could start')); | ||
} | ||
}); | ||
} |
{ | ||
"name": "selenium-standalone", | ||
"version": "3.0.3", | ||
"version": "3.1.0", | ||
"description": "installs a `selenium-standalone` command line to install and start a standalone selenium server", | ||
@@ -26,8 +26,7 @@ "main": "index.js", | ||
"commander": "^2.6.0", | ||
"debug": "^2.1.1", | ||
"lodash": "^2.4.1", | ||
"minimist": "^1.1.0", | ||
"mkdirp": "^0.5.0", | ||
"progress": "^1.1.8", | ||
"request": "^2.51.0", | ||
"rimraf": "^2.2.8", | ||
"unzip": "^0.1.11", | ||
@@ -34,0 +33,0 @@ "whereis": "^0.4.0" |
@@ -46,5 +46,9 @@ # selenium-standalone | ||
selenium.install({ | ||
// check for more recent versions of selenium here: | ||
// http://selenium-release.storage.googleapis.com/index.html | ||
version: '2.44.0', | ||
drivers: { | ||
chrome: { | ||
// check for more recent versions of chrome driver here: | ||
// http://chromedriver.storage.googleapis.com/index.html | ||
version: '2.13', | ||
@@ -54,5 +58,13 @@ arch: process.arch | ||
ie: { | ||
// check for more recent versions of internet explorer driver here: | ||
// http://selenium-release.storage.googleapis.com/index.html | ||
version: '2.44', | ||
arch: process.arch | ||
} | ||
}, | ||
logger: function(message) { | ||
}, | ||
progressCb: function(totalLength, progressLength, chunkLength) { | ||
} | ||
@@ -86,2 +98,6 @@ }, cb); | ||
`opts.progressCb(totalLength, progressLength, chunkLength)` will be called if provided with raw bytes length numbers about the current download process. It is used by the command line to show a progress bar. | ||
`opts.logger` will be called if provided with some debugging information about the installation process. | ||
`cb(err)` called when install finished or errored. | ||
@@ -100,2 +116,4 @@ | ||
`opts.spawnCb` will be called if provided as soon as the selenium child process was spawned. It may be interesting if you want to do some more debug. | ||
`cb(err, child)` called when the server is running and listening, child is the [ChildProcess](http://nodejs.org/api/child_process.html#child_process_class_childprocess) instance created. | ||
@@ -102,0 +120,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21906
9
20
388
135
3
+ Addedprogress@^1.1.8
+ Addedprogress@1.1.8(transitive)
- Removeddebug@^2.1.1
- Removedrimraf@^2.2.8
- Removeddebug@2.6.9(transitive)
- Removedms@2.0.0(transitive)