Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
vvo committed Sep 25, 2013
0 parents commit 0ffbed6
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
.selenium
18 changes: 18 additions & 0 deletions LICENSE
@@ -0,0 +1,18 @@
This software is released under the MIT license:

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13 changes: 13 additions & 0 deletions README.md
@@ -0,0 +1,13 @@
# selenium-standalone

Intalls a `start-selenium` command line starting a selenium standalone
server along with the chromedriver.

Currently installs selenium `2.35.0` and chrome driver `2.3`.

```shell
npm install start-selenium -g
start-selenium
```

`selenium-standalone` versions maps `selenium` versions.
11 changes: 11 additions & 0 deletions bin/start-selenium
@@ -0,0 +1,11 @@
#!/usr/bin/env node
var spawn = require('child_process').spawn;
var conf = require('../conf.js');

spawn('java', [
'-jar',
conf.selenium.path,
'-Dwebdriver.chrome.driver=' + conf.chromeDr.path
], {
stdio: 'inherit'
});
16 changes: 16 additions & 0 deletions conf.js
@@ -0,0 +1,16 @@
var path = require('path');

// see https://code.google.com/p/selenium/downloads/list for latest
var version = '2.35.0';

module.exports = {
selenium: {
path: path.join(__dirname, '.selenium', version, 'server.jar'),
v: version
},
chromeDr: {
path: path.join(__dirname, '.selenium', version, 'chromedriver'),
// see https://code.google.com/p/chromedriver/downloads/list
v: '2.3'
}
};
89 changes: 89 additions & 0 deletions install.js
@@ -0,0 +1,89 @@
var conf = require('./conf.js');
var async = require('async');

async.parallel([
installChromeDr.bind(null, conf.chromeDr.path, conf.chromeDr.v),
installSelenium.bind(null, conf.selenium.path, conf.selenium.v)
], function(err) {
if (err) {
throw err
}
});

function installSelenium(to, version, cb) {
var seleniumStandaloneUrl = 'https://selenium.googlecode.com/files/selenium-server-standalone-%s.jar'
var util = require('util');
var dl = util.format(seleniumStandaloneUrl, version);
var request = require('request');
var fstream = require('fstream');
var destination = fstream.Writer({
path: to,
type: 'File'
});

destination.on('error', cb);
destination.on('close', cb);

console.log('Downloading ' + dl);
request(dl)
.on('error', cb)
.pipe(destination);
}

function installChromeDr(to, version, cb) {
var path = require('path');
var util = require('util');

var chromedriverUrl = 'https://chromedriver.googlecode.com/files/chromedriver_%s_%s.zip';
var platform = getChromeDriverPlatform();

if(platform instanceof Error) {
return cb(platform);
}

var dl = util.format(chromedriverUrl, platform, version);

console.log('Downloading ' + dl);
downloadAndExtractZip(dl, path.dirname(to), function(err) {
if (err) {
return cb(err);
}

var fs = require('fs');
fs.chmod(to, '0755', cb);
});
}

function downloadAndExtractZip(from, to, cb) {
var fstream = require('fstream');
var request = require('request');
var unzip = require('unzip');
var destination = fstream.Writer({
path: to,
type: 'Directory'
});

destination.on('close', cb);
destination.on('error', cb);

request(from)
.on('error', cb)
.pipe(unzip.Parse())
.pipe(destination)
}

function getChromeDriverPlatform() {
var platform;

if (process.platform === 'linux') {
platform = 'linux' + ( process.arch === '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;
}
19 changes: 19 additions & 0 deletions package.json
@@ -0,0 +1,19 @@
{
"name": "selenium-standalone",
"version": "0.0.0",
"description": "installs a `start-selenium` command line to start a standalone selenium server with chrome-driver",
"dependencies": {
"request": "~2.27.0",
"unzip": "~0.1.9",
"async": "~0.2.9",
"fstream": "~0.1.24"
},
"bin": {
"start-selenium": "./bin/start-selenium"
},
"scripts": {
"install": "node install.js"
},
"author": "Vincent Voyer <vincent.voyer@gmail.com>",
"license": "MIT"
}

0 comments on commit 0ffbed6

Please sign in to comment.