Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nightwatch

Package Overview
Dependencies
Maintainers
1
Versions
355
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nightwatch - npm Package Compare versions

Comparing version 0.2.4 to 0.2.5

bin/chromedriver

34

bin/_cli.js

@@ -6,3 +6,3 @@ /**

module.exports = (function() {
module.exports = new (function() {

@@ -56,18 +56,20 @@ var _DEFAULTS_ = {};

return {
showHelp : function() {
return opt.showHelp();
},
command : function(name) {
if (_COMMANDS_[name]) {
return _COMMANDS_[name];
}
_COMMANDS_[name] = new Command(name);
return _COMMANDS_[name];
},
init : function() {
return opt.usage('Usage: $0 [options]').options(_DEFAULTS_).argv;
this.showHelp = function() {
return opt.showHelp();
};
this.command = function(name) {
if (_COMMANDS_[name]) {
return _COMMANDS_[name];
}
};
_COMMANDS_[name] = new Command(name);
return _COMMANDS_[name];
};
this.init = function() {
return opt.usage('Usage: $0 [options]').options(_DEFAULTS_).argv;
}
})();
/**
* Module dependencies
*/
var fs = require('fs'),
path = require('path'),
Logger = require('../lib/logger.js'),
cli = require('./_cli.js');
var fs = require('fs');
var path = require('path');
var Logger = require('../lib/logger.js');
var cli = require('./_cli.js');

@@ -105,2 +105,3 @@

} catch (ex) {
Logger.error(ex);
settings = {};

@@ -149,4 +150,5 @@ }

// the selenium runner
// the test runner
var runner = require(__dirname + '/../runner/run.js');
var settings = readSettings(argv);

@@ -175,18 +177,25 @@

// running the tests
runner.startSelenium(settings, test_settings, function(error, child, error_out, exitcode) {
if (error) {
Logger.error('There was an error while starting the Selenium server:');
console.log(error_out);
process.exit(exitcode);
}
if (settings.selenium && settings.selenium.start_process) {
var selenium = require(__dirname + '/../runner/selenium.js');
selenium.startServer(settings, test_settings, function(error, child, error_out, exitcode) {
if (error) {
Logger.error('There was an error while starting the Selenium server:');
console.log(error_out);
process.exit(exitcode);
}
runner.run(testsource, test_settings, {
output_folder : output_folder,
selenium : (settings.selenium || null)
}, function() {
selenium.stopServer();
});
});
} else {
runner.run(testsource, test_settings, {
output_folder : output_folder,
selenium : (settings.selenium || null)
}, function() {
if (settings.selenium && settings.selenium.start_process) {
runner.stopSelenium();
}
});
});
}
}

@@ -193,0 +202,0 @@ } catch (ex) {

@@ -7,4 +7,4 @@ {

"selenium" : {
"start_process" : true,
"server_path" : "./bin/selenium-server-standalone-2.39.0.jar",
"start_process" : false,
"server_path" : "",
"log_path" : "",

@@ -23,2 +23,3 @@ "host" : "127.0.0.1",

"firefox_profile" : false,
"chrome_driver" : "",
"screenshots" : {

@@ -25,0 +26,0 @@ "enabled" : false,

@@ -38,4 +38,3 @@ /**

.waitForElementVisible('button[name=btnG]', 1000)
.setValue('input[type=text]', '2 nightwatch')
.pause();
//.setValue('input[type=text]', '2 nightwatch')
},

@@ -42,0 +41,0 @@

@@ -451,3 +451,3 @@ var util = require("util"),

.on('error', function(data, err) {
console.error(Logger.colors.red("Connection refused!"), "Is selenium server started?", err);
console.error(Logger.colors.red("Connection refused!"), "Is selenium server started?");
self.emit('error', data, err);

@@ -454,0 +454,0 @@ })

{
"name": "nightwatch",
"description": "A node.js bindings implementation for selenium 2.0/webdriver",
"version": "0.2.4",
"version": "0.2.5",
"author": {

@@ -6,0 +6,0 @@ "name": "Andrei Rusu",

@@ -1,5 +0,4 @@

NightWatch
==========
# Nightwatch
[![Build Status](https://travis-ci.org/beatfactor/nightwatch.png?branch=master)](https://travis-ci.org/beatfactor/nightwatch)
[![Build Status](https://travis-ci.org/beatfactor/nightwatch.png?branch=master)](https://travis-ci.org/beatfactor/nightwatch) [![NPM version](https://badge.fury.io/js/nightwatch.png)](http://badge.fury.io/js/nightwatch)

@@ -9,10 +8,5 @@ UI automated testing framework based on [Node.js](http://nodejs.org/) and [Selenium WebDriver](http://docs.seleniumhq.org/projects/webdriver/)

***
## Quick Start
## Developer Guide
[http://nightwatchjs.org/guide](http://nightwatchjs.org/guide)
#### [Homepage](http://nightwatchjs.org) | [Developer Guide](http://nightwatchjs.org/guide) | [API Reference](http://nightwatchjs.org/api)
## API Reference
[http://nightwatchjs.org/api](http://nightwatchjs.org/api)
### Selenium WebDriver standalone server

@@ -23,3 +17,3 @@

### Install NightWatch
### Install Nightwatch

@@ -26,0 +20,0 @@ Install Node.js and then:

@@ -1,284 +0,154 @@

var path = require('path'),
fs = require('fs'),
child_process = require('child_process'),
nightwatch = require('../index.js'),
Logger = require("../lib/logger.js"),
Reporter = require('./reporters/junit.js'),
seleniumProcess = null,
util = require('util'),
globalresults = {
passed:0,
failed:0,
errors:0,
skipped:0,
tests:0,
errmessages:[],
modules:{}
/**
* Module dependencies
*/
var path = require('path');
var fs = require('fs');
var util = require('util');
var child_process = require('child_process');
var Nightwatch = require('../index.js');
var Logger = require('../lib/logger.js');
var Reporter = require('./reporters/junit.js');
module.exports = new (function() {
var seleniumProcess = null;
var globalresults = {
passed : 0,
failed : 0,
errors : 0,
skipped : 0,
tests : 0,
errmessages : [],
modules : {}
};
function runModule(module, opts, moduleName, callback) {
var client = Nightwatch.client(opts);
var keys = Object.keys(module);
var tests = [];
var setUp;
var tearDown;
var testresults = {
passed : 0,
failed : 0,
errors : 0,
skipped : 0,
tests : 0,
steps : keys.slice(0)
};
exports.run = function runner(files, opts, aditional_opts, finishCallback) {
var start = new Date().getTime();
var modules = {}
var curModule;
module.client = client;
if (typeof files == 'string') {
var paths = [files];
} else {
paths = files.map(function (p) {
return path.join(process.cwd(), p);
});
}
if (paths.length == 0) {
throw new Error('No tests to run.');
}
runFiles(paths, function runTestModule(err, fullpaths) {
if (!fullpaths || fullpaths.length == 0) {
Logger.warn('No tests defined!');
console.log('using source folder', paths)
return;
if (keys.indexOf('setUp') > -1) {
setUp = function(clientFn) {
module.setUp(module.client);
clientFn();
};
keys.splice(keys.indexOf('setUp'), 1);
testresults.steps.splice(testresults.steps.indexOf('setUp'), 1);
} else {
setUp = function(callback) {callback();}
}
var modulePath = fullpaths.shift();
var module = require(modulePath);
var moduleName = modulePath.split('/').pop();
globalresults.modules[moduleName] = [];
console.log("\n" + Logger.colors.cyan('[ ' + moduleName + ' module ]'));
runModule(module, opts, moduleName, function(testresults) {
globalresults.passed += testresults.passed;
globalresults.failed += testresults.failed;
globalresults.errors += testresults.errors;
globalresults.skipped += testresults.skipped;
globalresults.tests += testresults.tests;
if (keys.indexOf('tearDown') > -1) {
tearDown = function(clientFn) {
module.tearDown();
clientFn();
};
keys.splice(keys.indexOf('tearDown'), 1);
testresults.steps.splice(testresults.steps.indexOf('tearDown'), 1);
if (fullpaths.length) {
setTimeout(function() {
runTestModule(err, fullpaths);
}, 0);
} else {
if (testresults.tests != globalresults.tests || testresults.steps.length > 1) {
printResults(globalresults);
} else {
tearDown = function(callback) {callback();}
}
function next() {
if (keys.length) {
var key = keys.shift();
if (typeof module[key] != 'function') {
next();
return;
}
var output = aditional_opts.output_folder;
if (output === false) {
finishCallback();
} else {
ensureDir(output, function() {
Reporter.save(globalresults, output);
finishCallback();
});
console.log('\nRunning: ', Logger.colors.green(key));
var test = wrapTest(setUp, tearDown, module[key], module, function onComplete(results, errors) {
globalresults.modules[moduleName][key] = {
passed : results.passed,
failed : results.failed,
errors : results.errors,
skipped : results.skipped,
tests : [].concat(results.tests)
};
if (Array.isArray(errors) && errors.length) {
globalresults.errmessages = globalresults.errmessages.concat(errors);
}
testresults.passed += results.passed;
testresults.failed += results.failed;
testresults.errors += results.errors;
testresults.skipped += results.skipped;
testresults.tests += results.tests.length;
if (this.client.terminated) {
callback(testresults);
} else {
setTimeout(next, 0);
}
});
var error = false;
try {
test(client);
} catch (err) {
globalresults.errmessages.push(err.message);
console.log(Logger.colors.red('\nAn error occured while running the test:'));
console.log(err.stack);
testresults.errors++;
client.terminate();
error = true;
}
}
})
}, opts);
};
exports.startSelenium = function (settings, test_settings, callback) {
if (!settings.selenium || !settings.selenium.start_process) {
callback();
return;
}
util.print(Logger.colors.light_purple('Starting selenium server... '));
var selenium_port = settings.selenium.port || 4444;
var selenium_host = settings.selenium.host || "127.0.0.1";
var output = '', error_out = '';
var spawn = require('child_process').spawn;
var cliOpts = [
'-jar', settings.selenium.server_path,
'-port', selenium_port,
'-host', selenium_host
];
if (test_settings.firefox_profile) {
cliOpts.push('-Dwebdriver.firefox.profile=' + test_settings.firefox_profile);
}
seleniumProcess = spawn('java', cliOpts);
seleniumProcess.host = selenium_host;
seleniumProcess.port = selenium_port;
seleniumProcess.stdout.on('data', function(data) {
var sentinal = 'Started org.openqa.jetty.jetty.Server';
output += data.toString();
if (data.toString().indexOf(sentinal) != -1) {
seleniumProcess.removeListener('exit', exitHandler);
util.print(Logger.colors.light_purple('started - PID: ' ) + ' ' + seleniumProcess.pid + "\n" + Logger.colors.light_green("Running tests") + "\n");
callback(null, seleniumProcess);
if (!error) {
client.start();
}
} else {
callback(testresults);
}
}
});
seleniumProcess.stderr.on('data', function(data) {
output += data.toString();
error_out += data.toString();
});
var exitHandler = function(code) {
callback('Could not start Selenium.', null, error_out, code);
setTimeout(next, 0);
};
var closeHandler = function() {
fs.writeFile(path.join(settings.selenium.log_path, 'selenium_out.log'), output, "utf8", function(err) {
if (err) {
Logger.error(err);
function printResults(testresults) {
if (testresults.passed > 0 && testresults.errors == 0 && testresults.failed == 0) {
console.log(Logger.colors.green('\nOK. ' + testresults.passed, Logger.colors.background.black), 'total assertions passed.');
} else {
var skipped = '';
if (testresults.skipped) {
skipped = ' and ' + Logger.colors.blue(testresults.skipped) + ' skipped.';
}
});
Logger.info("Selenium process finished.");
};
seleniumProcess.on('exit', exitHandler);
seleniumProcess.on('close', closeHandler);
}
function killSeleniumProcess() {
var command = "ps -ax | grep [s]elenium | awk {'print $1 '} | xargs kill";
}
exports.stopSelenium = function(callback) {
callback = callback || function() {};
if (!seleniumProcess || seleniumProcess.killed) {
Logger.warn("Selenium process is not started.");
callback(false);
return;
}
try {
seleniumProcess.kill();
callback(true);
} catch (e) {
Logger.warn("Selenium process could not be stopped.");
console.log(e);
callback(false);
}
}
function printResults(testresults) {
if (testresults.passed > 0 && testresults.errors == 0 && testresults.failed == 0) {
console.log(Logger.colors.green("\nOK. " + testresults.passed, Logger.colors.background.black), 'total assertions passed.');
} else {
var skipped = '';
if (testresults.skipped) {
skipped = ' and ' + Logger.colors.blue(testresults.skipped) + ' skipped.';
console.log(Logger.colors.light_red('\nTEST FAILURE:'), Logger.colors.red(testresults.errors + testresults.failed) +
' assertions failed, ' + Logger.colors.green(testresults.passed) + ' passed' + skipped);
}
console.log(Logger.colors.light_red("\nTEST FAILURE:"), Logger.colors.red(testresults.errors + testresults.failed) +
' assertions failed, ' + Logger.colors.green(testresults.passed) + ' passed' + skipped);
}
}
function runModule(module, opts, moduleName, callback) {
var client = nightwatch.client(opts);
var keys = Object.keys(module);
var tests = [];
var testresults = {
passed:0,
failed:0,
errors:0,
skipped:0,
tests:0,
steps:keys.slice(0)
};
var setUp, tearDown;
module.client = client;
if (keys.indexOf('setUp') > -1) {
setUp = function(clientFn) {
module.setUp(module.client);
clientFn();
};
keys.splice(keys.indexOf('setUp'), 1);
testresults.steps.splice(testresults.steps.indexOf('setUp'), 1);
} else {
setUp = function(callback) {callback();}
}
if (keys.indexOf('tearDown') > -1) {
tearDown = function(clientFn) {
module.tearDown();
clientFn();
};
keys.splice(keys.indexOf('tearDown'), 1);
testresults.steps.splice(testresults.steps.indexOf('tearDown'), 1);
} else {
tearDown = function(callback) {callback();}
}
function next() {
if (keys.length) {
var key = keys.shift();
if (typeof module[key] != "function") {
next();
return;
}
console.log("\nRunning: ", Logger.colors.green(key));
var test = wrapTest(setUp, tearDown, module[key], module, function onComplete(results, errors) {
globalresults.modules[moduleName][key] = {
passed : results.passed,
failed : results.failed,
errors : results.errors,
skipped : results.skipped,
tests : [].concat(results.tests)
};
function wrapTest(setUp, tearDown, fn, context, onComplete) {
return function (client) {
context.client = client;
var clientFn = function () {
client.once('queue:finished', function(results, errors) {
tearDown.call(context, function() {
onComplete.call(context, results, errors);
});
});
if (Array.isArray(errors) && errors.length) {
globalresults.errmessages = globalresults.errmessages.concat(errors);
}
testresults.passed += results.passed;
testresults.failed += results.failed;
testresults.errors += results.errors;
testresults.skipped += results.skipped;
testresults.tests += results.tests.length;
if (this.client.terminated) {
callback(testresults);
} else {
setTimeout(next, 0);
}
});
return fn.call(context, client);
};
var error = false;
try {
test(client);
} catch (err) {
globalresults.errmessages.push(err.message);
console.log(Logger.colors.red("\nAn error occured while running the test:"));
console.log(err.stack);
testresults.errors++;
client.terminate();
error = true;
}
if (!error) {
client.start();
}
} else {
callback(testresults);
}
}
setTimeout(next, 0);
}
function wrapTest(setUp, tearDown, fn, context, onComplete) {
return function (client) {
context.client = client;
var clientFn = function () {
client.once('queue:finished', function(results, errors) {
tearDown.call(context, function() {
onComplete.call(context, results, errors);
});
});
return fn.call(context, client);
setUp.call(context, clientFn);
return;
};
setUp.call(context, clientFn);
return;
};
};
function ensureDir(path, callback) {
function ensureDir(path, callback) {
var mkdir = child_process.spawn('mkdir', ['-p', path]);

@@ -293,73 +163,133 @@ mkdir.on('error', function (err) {

});
};
function runFiles(paths, cb, opts) {
var extensionPattern = /\.js$/;
if (paths.length == 1 && extensionPattern.test(paths[0])) {
paths[0] = paths[0].replace(extensionPattern, '');
return cb(null, paths);
}
};
paths.forEach(function(p) {
walk(p, function(err, list) {
function runFiles(paths, cb, opts) {
var extensionPattern = /\.js$/;
if (paths.length == 1 && extensionPattern.test(paths[0])) {
paths[0] = paths[0].replace(extensionPattern, '');
return cb(null, paths);
}
paths.forEach(function(p) {
walk(p, function(err, list) {
if (err) {
return cb(err);
}
list.sort();
var modules = list.filter(function (filename) {
return extensionPattern.exec(filename);
});
modules = modules.map(function (filename) {
return filename.replace(extensionPattern, '');
});
cb(null, modules);
}, opts);
});
};
function walk(dir, done, opts) {
var results = [];
fs.readdir(dir, function(err, list) {
if (err) {
return cb(err);
return done(err);
}
list.sort();
var pending = list.length;
var modules = list.filter(function (filename) {
return extensionPattern.exec(filename);
if (pending == 0) {
return done(null, results);
}
list.forEach(function(file) {
file = [dir, file].join('/');
fs.stat(file, function(err, stat) {
if (stat && stat.isDirectory()) {
var dirname = file.split('/').slice(-1)[0];
if (opts.skipgroup && opts.skipgroup.indexOf(dirname) > -1) {
pending = pending-1;
} else {
walk(file, function(err, res) {
results = results.concat(res);
pending = pending-1;
if (!pending) {
done(null, results);
}
}, opts);
}
} else {
results.push(file);
pending = pending-1;
if (!pending) {
done(null, results);
}
}
});
});
});
};
this.run = function runner(files, opts, aditional_opts, finishCallback) {
var start = new Date().getTime();
var modules = {}
var curModule;
modules = modules.map(function (filename) {
return filename.replace(extensionPattern, '');
if (typeof files == 'string') {
var paths = [files];
} else {
paths = files.map(function (p) {
return path.join(process.cwd(), p);
});
cb(null, modules);
}, opts);
});
}
var walk = function(dir, done, opts) {
var results = [];
fs.readdir(dir, function(err, list) {
if (err) {
return done(err);
}
var pending = list.length;
if (pending == 0) {
return done(null, results);
if (paths.length == 0) {
throw new Error('No tests to run.');
}
list.forEach(function(file) {
file = [dir, file].join('/');
runFiles(paths, function runTestModule(err, fullpaths) {
if (!fullpaths || fullpaths.length == 0) {
Logger.warn('No tests defined!');
console.log('using source folder', paths)
return;
}
fs.stat(file, function(err, stat) {
if (stat && stat.isDirectory()) {
var dirname = file.split('/').slice(-1)[0];
if (opts.skipgroup && opts.skipgroup.indexOf(dirname) > -1) {
pending = pending-1;
var modulePath = fullpaths.shift();
var module = require(modulePath);
var moduleName = modulePath.split('/').pop();
globalresults.modules[moduleName] = [];
console.log('\n' + Logger.colors.cyan('[ ' + moduleName + ' module ]'));
runModule(module, opts, moduleName, function(testresults) {
globalresults.passed += testresults.passed;
globalresults.failed += testresults.failed;
globalresults.errors += testresults.errors;
globalresults.skipped += testresults.skipped;
globalresults.tests += testresults.tests;
if (fullpaths.length) {
setTimeout(function() {
runTestModule(err, fullpaths);
}, 0);
} else {
if (testresults.tests != globalresults.tests || testresults.steps.length > 1) {
printResults(globalresults);
}
var output = aditional_opts.output_folder;
if (output === false) {
finishCallback();
} else {
walk(file, function(err, res) {
results = results.concat(res);
pending = pending-1;
if (!pending) {
done(null, results);
}
}, opts);
ensureDir(output, function() {
Reporter.save(globalresults, output);
finishCallback();
});
}
} else {
results.push(file);
pending = pending-1;
if (!pending) {
done(null, results);
}
}
});
});
});
};
})
}, opts);
};
})();

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc