grunt-protractor-webdriver
Advanced tools
Comparing version
{ | ||
"name": "grunt-protractor-webdriver", | ||
"description": "grunt plugin for starting Protractor's bundled Selenium Webdriver", | ||
"version": "0.1.2", | ||
"version": "0.1.4", | ||
"homepage": "https://github.com/seckardt/grunt-protractor-webdriver", | ||
@@ -29,13 +29,14 @@ "author": { | ||
"grunt-contrib-clean": "~0.5.0", | ||
"protractor": "~0.16.1", | ||
"protractor": "~0.17.0", | ||
"grunt": "~0.4.2" | ||
}, | ||
"peerDependencies": { | ||
"grunt": "~0.4.0", | ||
"protractor": ">= 0.14.0" | ||
"grunt": ">=0.4.0", | ||
"protractor": ">=0.14.0" | ||
}, | ||
"keywords": [ | ||
"gruntplugin", | ||
"protractor" | ||
"protractor", | ||
"webdriver" | ||
] | ||
} |
@@ -1,5 +0,7 @@ | ||
# grunt-protractor-webdriver | ||
# grunt-protractor-webdriver [](https://david-dm.org/seckardt/grunt-protractor-webdriver#info=devDependencies) [](http://badge.fury.io/js/grunt-protractor-webdriver) [](http://gruntjs.com/) | ||
> grunt plugin for starting Protractor's bundled Selenium Webdriver | ||
[](https://nodei.co/npm/grunt-protractor-webdriver.png?downloads=true&stars=true) | ||
This `Grunt` task starts a Selenium Webdriver, blocks until it's ready to accept connections, and then leaves it running in the background until the `Grunt` process finished. During startup it checks for already running Webdriver instances and at the end of the `Grunt` process also shuts down the Selenium server to not leave you with any zombies. | ||
@@ -83,2 +85,4 @@ | ||
* v0.1.4 - No code changes. Just had to push new release as v0.1.3 seems to be lost in the NPM repo... | ||
* v0.1.3 - Fix regression of v0.1.2 with wrong Selenium server path being used. Add additional exit handlers for `.on('error')`, `.on('uncaughtException')` and `.on('SIGINT')`. | ||
* v0.1.2 - Harden waiting for all browser sessions to be deleted before shutdown. Due to possible race-conditions with log statements for multiple browser sessions in one line, the session counter didn't work properly. | ||
@@ -85,0 +89,0 @@ * v0.1.1 - Ensure waiting for eventual `Selenium is already running` message on failure. Ensure waiting for all browser sessions to be deleted before shutdown. |
@@ -20,2 +20,3 @@ /** | ||
http = require('http'), | ||
rl = require('readline'), | ||
noop = function () {}, | ||
@@ -36,18 +37,21 @@ REGEXP_REMOTE = /RemoteWebDriver instances should connect to: (.*)/, | ||
function exec(command) { | ||
var file, | ||
args, | ||
opts = { | ||
cwd: process.cwd(), | ||
stdio: [process.stdin] | ||
}; | ||
var opts = { | ||
cwd: process.cwd(), | ||
stdio: [process.stdin] | ||
}; | ||
if (process.platform === 'win32') { | ||
file = 'cmd.exe'; | ||
args = ['/s', '/c', command.replace(/\//g, '\\')]; | ||
opts.windowsVerbatimArguments = true; | ||
var child = spawn('cmd.exe', ['/s', '/c', command.replace(/\//g, '\\')], opts); | ||
rl.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout | ||
}).on('SIGINT', function () { | ||
process.emit('SIGINT'); | ||
}); | ||
return child; | ||
} else { | ||
file = '/bin/sh'; | ||
args = ['-c', command]; | ||
return spawn('/bin/sh', ['-c', command], opts); | ||
} | ||
return spawn(file, args, opts); | ||
} | ||
@@ -72,3 +76,3 @@ | ||
sessions = 0, // Running sessions | ||
status = [false, false], // [0 = Stopping, 1 = Stopped] | ||
status = [false, false, false],// [0 = Stopping, 1 = Stopped, 2 = exited] | ||
stopCallbacks = []; | ||
@@ -80,4 +84,7 @@ | ||
selenium = exec(options.path + options.command); | ||
selenium.on('exit', exit); | ||
selenium.on('close', exit); | ||
selenium.on('error', exit) | ||
.on('uncaughtException', exit) | ||
.on('exit', exit) | ||
.on('close', exit) | ||
.on('SIGINT', exit); | ||
@@ -101,3 +108,5 @@ selenium.stdout.setEncoding('utf8'); | ||
function stop(callback) { | ||
if (status[0] || status[1]) { | ||
if (status[2]) { | ||
callback(true); | ||
} else if (status[0] || status[1]) { | ||
stopCallbacks.push(callback); | ||
@@ -116,9 +125,10 @@ return; | ||
if (callback) { | ||
var success = status[1] = REGEXP_SHUTDOWN_OK.test(response); | ||
stopCallbacks.push(callback); | ||
var success = status[1] = REGEXP_SHUTDOWN_OK.test(response), | ||
callbacks = stopCallbacks.slice(); | ||
stopCallbacks = []; | ||
callbacks.push(callback); | ||
grunt.log.writeln('Shut down'.cyan + ' Selenium server: ' + server + ' (' + (success ? response.green : response.red) + ')'); | ||
stopCallbacks.forEach(function (cb) { | ||
callbacks.forEach(function (cb) { | ||
cb(success); | ||
}); | ||
stopCallbacks = []; | ||
} | ||
@@ -131,14 +141,18 @@ }); | ||
return function (callback) { | ||
if (status[0] || status[1]) { | ||
return; | ||
} | ||
var cb = function () { | ||
status[2] = true; | ||
proc.kill(); | ||
proc.stdout.destroy(); | ||
proc.stderr.destroy(); | ||
callback = callback || function () { | ||
grunt.fatal(stackTrace || 'Selenium terminated unexpectedly'); | ||
if (typeof callback === 'function') { | ||
callback(); | ||
} else { | ||
grunt.fatal(stackTrace || 'Selenium terminated unexpectedly'); | ||
} | ||
}; | ||
stop(callback); | ||
if (status[2]) { | ||
cb(); | ||
return; | ||
} | ||
stop(cb); | ||
}; | ||
@@ -152,3 +166,3 @@ } | ||
if (REGEXP_REMOTE.test(out)) { | ||
server = extract(REGEXP_REMOTE, out, 1) || server; | ||
server = extract(REGEXP_REMOTE, out, 1).replace(/\/wd\/hub/, '') || server; | ||
} else if (REGEXP_STARTED.test(out)) { | ||
@@ -155,0 +169,0 @@ // Success |
Sorry, the diff of this file is not supported yet
14704
9.59%257
5.76%93
4.49%