grunt-selenium-server
Advanced tools
Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "grunt-selenium-server", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Grunt task to start/stop a local Selenium standalon server.", | ||
@@ -5,0 +5,0 @@ "main": "Gruntfile.js", |
@@ -16,1 +16,63 @@ # grunt-selenium-server | ||
``` | ||
Grunt config example (with default options): | ||
```js | ||
'start-selenium-server': { | ||
dev: { | ||
options: { | ||
downloadUrl: 'https://selenium-release.storage.googleapis.com/2.42/selenium-server-standalone-2.42.2.jar', | ||
downloadLocation: '/tmp', | ||
serverOptions: {}, | ||
systemProperties: {} | ||
} | ||
} | ||
}, | ||
'stop-selenium-server': { | ||
dev: { | ||
} | ||
} | ||
``` | ||
Grunt task example: | ||
```js | ||
grunt.registerTask('devUI', 'run selenium server and phpunit', function(){ | ||
grunt.task.run(['start-selenium-server:dev', 'phpunit:dev', 'stop-selenium-server:dev']); | ||
}); | ||
``` | ||
Run: | ||
```shell | ||
grunt devUI | ||
``` | ||
Kill selenium in case your grunt tasks fails before we reach 'stop-selenium-server': | ||
```js | ||
var seleniumChildProcesses = {}; | ||
grunt.event.on('selenium.start', function(target, process){ | ||
grunt.log.ok('Saw process for target: ' + target); | ||
seleniumChildProcesses[target] = process; | ||
}); | ||
grunt.util.hooker.hook(grunt.fail, function(){ | ||
// Clean up selenium if we left it running after a failure. | ||
grunt.log.writeln('Attempting to clean up running selenium server.'); | ||
for(var target in seleniumChildProcesses) { | ||
grunt.log.ok('Killing selenium target: ' + target); | ||
try { | ||
seleniumChildProcesses[target].kill('SIGTERM'); | ||
} | ||
catch(e) { | ||
grunt.log.warn('Unable to stop selenium target: ' + target); | ||
} | ||
} | ||
}); | ||
``` | ||
## Notes: | ||
1. If you won't handle this event, if your phpunit (for example) will fail the selenium server process will remain active in the background. | ||
2. The "grunt.fail" event will be fired whenever any grunt task is failing. Thus you might want to consider using a more specific event related to the task that actually uses selenium server. i.e phpunit in the above example. | ||
@@ -5,2 +5,3 @@ | ||
var fs = require('fs'); | ||
var os = require('os'); | ||
var path = require('path'); | ||
@@ -39,2 +40,5 @@ var url = require('url'); | ||
request(options.downloadUrl).on('response', function (res) { | ||
if(res.statusCode >= 200 && res.statusCode < 300) { | ||
grunt.fail.fatal(options.downloadUrl + " returns " + res.statusCode); | ||
} | ||
// Full length of file. | ||
@@ -88,2 +92,6 @@ var len = parseInt(res.headers['content-length'], 10); | ||
Object.keys(options.systemProperties).forEach(function (key) { | ||
args.push('-D' + key + '=' + options.systemProperties[key]); | ||
}); | ||
grunt.log.ok('Starting Selenium server...'); | ||
@@ -103,3 +111,4 @@ | ||
childProcesses[target].stdout.on('data', function(data) { | ||
// Reading stream see if selenium has started | ||
function hasSeleniumStarted(data) { | ||
if (data.toString().match(/Started SocketListener on .+:\d+/)) { | ||
@@ -115,7 +124,8 @@ if (complete) return; | ||
} | ||
}); | ||
} | ||
childProcesses[target].stderr.on('data', function(data) { | ||
grunt.log.error(data.toString()); | ||
}); | ||
// < 2.43.0 outputs to stdout | ||
childProcesses[target].stdout.on('data', hasSeleniumStarted); | ||
// >= 2.43.0 outputs to stdout | ||
childProcesses[target].stderr.on('data', hasSeleniumStarted); | ||
@@ -128,3 +138,3 @@ // Timeout case | ||
childProcesses[target].kill('SIGTERM'); | ||
cb(new Error('Timeout waiting for selenium to start.')); | ||
cb(new Error('Timeout waiting for selenium to start. Check if an instance of selenium is already running.')); | ||
} | ||
@@ -143,5 +153,6 @@ }, 30000); | ||
var options = this.options({ | ||
downloadUrl: 'https://selenium.googlecode.com/files/selenium-server-standalone-2.42.2.jar', | ||
downloadLocation: '/tmp', | ||
serverOptions: {} | ||
downloadUrl: 'https://selenium-release.storage.googleapis.com/2.42/selenium-server-standalone-2.42.2.jar', | ||
downloadLocation: os.tmpdir(), | ||
serverOptions: {}, | ||
systemProperties: {} | ||
}); | ||
@@ -185,3 +196,2 @@ | ||
}); | ||
}; |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
8716
186
78
1