🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

grunt-protractor-webdriver

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-protractor-webdriver - npm Package Compare versions

Comparing version

to
0.1.1

2

package.json
{
"name": "grunt-protractor-webdriver",
"description": "grunt plugin for starting Protractor's bundled Selenium Webdriver",
"version": "0.1.0",
"version": "0.1.1",
"homepage": "https://github.com/seckardt/grunt-protractor-webdriver",

@@ -6,0 +6,0 @@ "author": {

@@ -83,3 +83,4 @@ # grunt-protractor-webdriver

* v0.1.0 - initial
* 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.
* v0.1.0 - Initial commit.

@@ -86,0 +87,0 @@ ## License

@@ -15,6 +15,5 @@ /**

*/
module.exports = function (grunt) {
'use strict';
'use strict';
module.exports = function (grunt) {
var spawn = require('child_process').spawn,

@@ -27,4 +26,7 @@ http = require('http'),

FAILURE_REGEXP = /Failed to start/,
DONE_REGEXP = /Executing: \[delete session: (.*)\]/,
SHUTDOWN_OK_REGEXP = /OKOK/,
SESSION_DELETE_REGEXP = /Executing: \[delete session: (.*)\]/,
SESSION_NEW_REGEXP = /Executing: \[new session: (.*)\]/,
EXCEPTION_REGEXP = /Exception thrown(.*)/m,
FATAL_REGEXP = /Fatal error/,
SHUTDOWN_OK_REGEXP = /OKOK/i,
DEFAULT_CMD = 'webdriver-manager start',

@@ -56,10 +58,15 @@ DEFAULT_INSTANCE = 'http://localhost:4444';

function Webdriver(context, options) {
function Webdriver(context, options, restarted) {
var done = context.async(),
restartedPrefix = (restarted === true ? 'Res' : 'S'),
selenium,
destroy,
server = DEFAULT_INSTANCE;
failureTimeout,
stackTrace,
server = DEFAULT_INSTANCE,
sessions = 0, // Running sessions
status = [false, false]; // [0 = Stopping, 1 = Stopped]
function start() {
grunt.log.writeln('Starting'.cyan + ' Selenium server');
grunt.log.writeln((restartedPrefix + 'tarting').cyan + ' Selenium server');

@@ -77,3 +84,4 @@ selenium = exec(options.path + options.command);

function started(callback) {
grunt.log.writeln('Started'.cyan + ' Selenium server: ' + server.green);
status[1] = false;
grunt.log.writeln((restartedPrefix + 'tarted').cyan + ' Selenium server: ' + server.green);
if (callback) {

@@ -85,2 +93,6 @@ callback();

function stop(callback) {
if (status[0] || status[1]) {
return;
}
status[0] = true;
grunt.log.writeln('Shutting down'.cyan + ' Selenium server: ' + server);

@@ -93,4 +105,5 @@

}).on('end', function () {
status[0] = false;
if (callback) {
var success = SHUTDOWN_OK_REGEXP.test(response);
var success = status[1] = SHUTDOWN_OK_REGEXP.test(response);
grunt.log.writeln('Shut down'.cyan + ' Selenium server: ' + server + ' (' + (success ? response.green : response.red) + ')');

@@ -105,2 +118,6 @@ callback(success);

return function (callback) {
if (status[0] || status[1]) {
return;
}
proc.stdout.destroy();

@@ -110,3 +127,3 @@ proc.stderr.destroy();

callback = callback || function () {
grunt.fatal('Selenium terminated unexpectedly');
grunt.fatal(stackTrace || 'Selenium terminated unexpectedly');
};

@@ -119,3 +136,3 @@

function data(out) {
grunt.verbose.writeln('SELENIUM: '.cyan + out);
grunt.verbose.writeln('>> '.red + out);

@@ -131,2 +148,6 @@ if (REMOTE_REGEXP.test(out)) {

} else if (RUNNING_REGEXP.test(out)) {
if (failureTimeout) {
clearTimeout(failureTimeout);
}
// Webdriver instance is already running -> Trying to shutdown

@@ -136,3 +157,3 @@ stop(function (success) {

// Shutdown succeeded -> Retry
new Webdriver(context, options);
new Webdriver(context, options, true);
} else {

@@ -144,7 +165,21 @@ // Shutdown failed -> Exit

} else if (FAILURE_REGEXP.test(out)) {
// Failure -> Exit after timeout. The timeout is needed to
// enable further console sniffing as the output needed to
// match `RUNNING_REGEXP` is coming behind the failure message.
failureTimeout = setTimeout(destroy, 500);
} else if (EXCEPTION_REGEXP.test(out)) {
// Failure -> Exit
grunt.log.writeln('Exception thrown.'.red + ' Going to shut down the Selenium server.');
stackTrace = out;
destroy();
} else if (DONE_REGEXP.test(out)) {
} else if (FATAL_REGEXP.test(out)) {
// Failure -> Exit
destroy();
} else if (SESSION_NEW_REGEXP.test(out)) {
sessions++;
} else if (SESSION_DELETE_REGEXP.test(out)) {
// Done -> Exit
destroy(noop);
if (--sessions <= 0) {
destroy(noop);
}
}

@@ -151,0 +186,0 @@ }