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.3.5 to 0.3.6

.jshintrc

34

bin/_cli.js

@@ -7,11 +7,11 @@ /**

module.exports = new (function() {
var _DEFAULTS_ = {};
var _COMMANDS_ = {};
function Command(name) {
this.name = name;
_DEFAULTS_[this.name] = {};
};
}
Command.prototype.demand = function(value) {

@@ -24,3 +24,3 @@ if (!value && _DEFAULTS_[this.name].demand) {

};
Command.prototype.description = function(value) {

@@ -33,3 +33,3 @@ if (!value && _DEFAULTS_[this.name].description) {

};
Command.prototype.alias = function(value) {

@@ -42,3 +42,3 @@ if (!value && _DEFAULTS_[this.name].alias) {

};
Command.prototype.defaults = function(value) {

@@ -51,3 +51,3 @@ if (!value && _DEFAULTS_[this.name]['default']) {

};
Command.prototype.isDefault = function(value) {

@@ -59,8 +59,8 @@ if (_DEFAULTS_[this.name]['default'] === value) {

};
this.showHelp = function() {
return opt.showHelp();
return opt.showHelp();
};
this.command = function(name) {

@@ -71,10 +71,10 @@ if (_COMMANDS_[name]) {

_COMMANDS_[name] = new Command(name);
return _COMMANDS_[name];
return _COMMANDS_[name];
};
this.init = function() {
return opt.usage('Usage: $0 [options]').options(_DEFAULTS_).argv;
};
})();
})();

@@ -123,3 +123,3 @@ /**

return settings;
};
}

@@ -142,2 +142,3 @@ /**

test_settings.custom_commands_path = settings.custom_commands_path || '';
test_settings.custom_assertions_path = settings.custom_assertions_path || '';

@@ -188,3 +189,5 @@ if (argv.verbose) {

argv.t;
testsource.substr(-3) === '.js' || (testsource += '.js');
if (testsource.substr(-3) != '.js') {
testsource += '.js';
}
fs.statSync(testsource);

@@ -191,0 +194,0 @@ } else if (typeof argv.g == 'string') {

@@ -5,3 +5,4 @@ {

"custom_commands_path" : "",
"custom_assertions_path" : "",
"selenium" : {

@@ -12,5 +13,5 @@ "start_process" : false,

"host" : "127.0.0.1",
"port" : 4444
"port" : 4444
},
"test_settings" : {

@@ -25,2 +26,3 @@ "default" : {

"chrome_driver" : "",
"ie_driver" : "",
"screenshots" : {

@@ -36,3 +38,3 @@ "enabled" : false,

},
"saucelabs" : {

@@ -55,3 +57,3 @@ "selenium_host" : "ondemand.saucelabs.com",

},
"browserstack" : {

@@ -58,0 +60,0 @@ "selenium_host" : "hub.browserstack.com",

@@ -20,6 +20,8 @@ var util = require('util'),

this.options.screenshots || (this.options.screenshots = {
'enabled' : false,
'path' : ''
});
if (!this.options.screenshots) {
this.options.screenshots = {
'enabled' : false,
'path' : ''
};
}

@@ -80,6 +82,7 @@ this.options.output = this.options.output || typeof this.options.output == 'undefined';

.loadAssertions();
if (this.options.custom_commands_path) {
this.loadCustomCommands();
}
};
}

@@ -109,3 +112,3 @@ util.inherits(Nightwatch, events.EventEmitter);

return this;
}
};

@@ -125,3 +128,3 @@ Nightwatch.prototype.terminate = function() {

return this;
}
};

@@ -133,3 +136,3 @@ Nightwatch.prototype.printResult = function() {

var ok = false;
if (this.results.failed == 0 && this.results.errors == 0) {
if (this.results.failed === 0 && this.results.errors === 0) {
ok = true;

@@ -140,3 +143,3 @@ }

console.log(Logger.colors.green('OK.'), Logger.colors.green(this.results.passed) + ' assertions passed.');
} else if (ok && this.results.passed == 0) {
} else if (ok && this.results.passed === 0) {
console.log(Logger.colors.green('No assertions ran.'));

@@ -176,3 +179,3 @@ } else {

this.results.tests.length = 0;
}
};

@@ -188,3 +191,3 @@ Nightwatch.prototype.loadProtocolActions = function() {

return this;
}
};

@@ -194,3 +197,3 @@ Nightwatch.prototype.loadCommands = function() {

return this;
}
};

@@ -215,3 +218,3 @@ Nightwatch.prototype.loadCustomCommands = function() {

});
}
};

@@ -231,7 +234,7 @@ Nightwatch.prototype.loadAssertions = function() {

var message = typeof arguments[arguments.length-1] == 'string' &&
(arguments.length > 2 || typeof arguments[0] === 'boolean') &&
arguments[arguments.length-1]
|| (typeof arguments[0] === 'function' && '[Function]')
|| '' + actual;
message = typeof arguments[arguments.length-1] == 'string' &&
(arguments.length > 2 || typeof arguments[0] === 'boolean') &&
arguments[arguments.length-1] ||
(typeof arguments[0] === 'function' && '[Function]') ||
'' + actual;

@@ -246,6 +249,6 @@ try {

actual = ex.actual;
expected = ex.expected
expected = ex.expected;
}
return self.assertion(passed, actual, expected, message, true);
}
};
})(prop);

@@ -256,9 +259,18 @@ }

this.loadAssertionFiles(this.assert, true);
}
if (this.options.custom_assertions_path) {
this.loadCustomAssertions(this.assert, true);
}
};
Nightwatch.prototype.addVerifyTests = function() {
this.verify = {};
this.loadAssertionFiles(this.verify, false);
if (this.options.custom_assertions_path) {
this.loadCustomAssertions(this.verify, false);
}
return this;
}
};

@@ -268,6 +280,2 @@ Nightwatch.prototype.loadAssertionFiles = function(parent, abortOnFailure) {

var commandFiles = fs.readdirSync(path.join(__dirname, relativePath));
var AbstractAssertion = function(abortOnFailure, client) {
this.abortOnFailure = abortOnFailure;
this.client = client;
}

@@ -283,4 +291,20 @@ for (var i = 0, len = commandFiles.length; i < len; i++) {

}
}
};
Nightwatch.prototype.loadCustomAssertions = function(parent, abortOnFailure) {
var absPath = path.join(process.cwd(), this.options.custom_assertions_path);
var assertionFiles = fs.readdirSync(absPath);
var self = this;
assertionFiles.forEach(function(file) {
if (path.extname(file) == '.js') {
var Module = require(path.join(absPath, file));
var name = path.basename(file, '.js');
var m = new Module();
AbstractAssertion.call(m, abortOnFailure, self);
self.addCommand(name, m.command, m, parent);
}
});
};
Nightwatch.prototype.addCommand = function(name, command, context, parent) {

@@ -291,3 +315,3 @@ parent = parent || this;

var error = new Error('The command "' + name + '" is already defined!');
this.errors.push(error.stack)
this.errors.push(error.stack);
throw error;

@@ -325,13 +349,13 @@ }

var d = new Date();
var datestamp = d.toLocaleString('en-GB', {
weekday: 'narrow',
year: 'numeric',
month: '2-digit',
day: '2-digit',
timeZoneName : 'short',
hour : '2-digit',
minute : '2-digit',
second : '2-digit',
era : 'short'
}).replace(/\:/g,'').replace(/\s/g,'-').replace(/-\(.+?\)/,'');
var datestamp = d.toLocaleString('en-GB', {
weekday: 'narrow',
year: 'numeric',
month: '2-digit',
day: '2-digit',
timeZoneName : 'short',
hour : '2-digit',
minute : '2-digit',
second : '2-digit',
era : 'short'
}).replace(/:/g,'').replace(/\s/g,'-').replace(/-\(.+?\)/,'');
var fileName = path.join(self.options.screenshots.path, 'ERROR_' + datestamp + '.png');

@@ -365,3 +389,3 @@ self.saveScreenshotToFile(fileName, screenshotContent);

return request
return request;
};

@@ -378,3 +402,3 @@

var error = new Error('No such command: ' + commandName);
this.errors.push(error.stack)
this.errors.push(error.stack);
throw error;

@@ -384,15 +408,8 @@ }

return this.queue.run();
}
};
Nightwatch.prototype.executeCommand = function(command) {
util.inherits(command, events.EventEmitter);
var instance = new command();
events.EventEmitter.call(instance)
return instance;
}
Nightwatch.prototype.getElement = function(using, value, callback) {
var self = this;
return this.runCommand('element', [using, value, function(result) {
if (result.status == 0) {
if (result.status === 0) {
callback.call(self, result.value.ELEMENT, result);

@@ -405,3 +422,3 @@ } else {

Nightwatch.prototype.assertion = function(passed, receivedValue, expectedValue, message, abortOnFailure) {
Nightwatch.prototype.assertion = function(passed, receivedValue, expectedValue, message, abortOnFailure, stripExpected) {
var failure = '', stacktrace = '';

@@ -423,5 +440,7 @@

} catch (ex) {
stripExpected = stripExpected || false;
var logged = Logger.colors.red('✖') + ' ' + message;
if (typeof expectedValue != 'undefined' && typeof receivedValue != 'undefined') {
logged += ' ' + Logger.colors.white(' - expected ' + Logger.colors.green('"' + expectedValue + '"')) + ' but got: ' + Logger.colors.red(receivedValue);
logged += stripExpected ? (' ' + Logger.colors.white(' - expected ' + Logger.colors.green('"' +
expectedValue + '"')) + ' but got: ' + Logger.colors.red(receivedValue)) : '';
}

@@ -446,3 +465,3 @@

}
return this
return this;
};

@@ -454,3 +473,3 @@

if (err) {
console.log(Logger.colors.yellow('Couldn\'t save screenshot to '), fileName);
console.log(Logger.colors.yellow('Couldn\'t save screenshot to '), fileName);
Logger.warn(err);

@@ -509,5 +528,10 @@ }

function AbstractAssertion(abortOnFailure, client) {
this.abortOnFailure = abortOnFailure;
this.client = client;
}
exports.client = function(options) {
return new Nightwatch(options);
}
};

@@ -96,2 +96,3 @@ var util = require('util'),

}
if (result.value.message && shouldLogErrorMessage(result.value.message)) {

@@ -98,0 +99,0 @@ errorMessage = result.value.message.replace(/\n/g,'\n\t');

@@ -12,3 +12,3 @@ var Protocol = require('../protocol.js'),

this.selector = null;
};
}

@@ -19,17 +19,17 @@ util.inherits(CommandAction, events.EventEmitter);

if (typeof milliseconds != 'number') {
throw new Error('waitForElementPresent expects second parameter to be number; ' +
throw new Error('waitForElementPresent expects second parameter to be number; ' +
typeof (milliseconds) + ' given');
}
this.startTimer = new Date().getTime();
if (typeof arguments[2] == 'boolean') {
this.abortOnFailure = arguments[2];
this.cb = arguments[3] || function() {};
this.cb = arguments[3] || function() {};
} else {
this.cb = callbackOrAbort || function() {};
this.cb = callbackOrAbort || function() {};
}
this.ms = milliseconds;
this.selector = cssSelector;
this.checkElement();
this.selector = cssSelector;
this.checkElement();
return this;

@@ -42,6 +42,7 @@ };

var now = new Date().getTime();
var msg;
if (result.status === 0) {
self.cb(result.value);
var msg = "Element <" + self.selector + "> was present after " + (now - self.startTimer) + " milliseconds.";
self.client.assertion(true, result.value, '!false', msg, true);
self.cb(result.value);
msg = "Element <" + self.selector + "> was present after " + (now - self.startTimer) + " milliseconds.";
self.client.assertion(true, result.value, '!false', msg, true, false);
return self.emit('complete');

@@ -51,12 +52,12 @@ } else if (now - self.startTimer < self.ms) {

self.checkElement();
}, 500);
}, 500);
} else {
self.cb(false);
var msg = "Timed out while waiting for element <" + self.selector + "> to be present for " + self.ms + " milliseconds.";
self.client.assertion(false, false, false, msg, self.abortOnFailure);
return self.emit('complete');
msg = "Timed out while waiting for element <" + self.selector + "> to be present for " + self.ms + " milliseconds.";
self.client.assertion(false, false, false, msg, self.abortOnFailure, false);
return self.emit('complete');
}
});
};
module.exports = CommandAction;
{
"name": "nightwatch",
"description": "A node.js bindings implementation for selenium 2.0/webdriver",
"version": "0.3.5",
"version": "0.3.6",
"author": {

@@ -23,3 +23,4 @@ "name": "Andrei Rusu",

"optimist": ">=0.3.5",
"minimatch": "~0.2.14"
"minimatch": "~0.2.14",
"mkpath": ">=0.1.0"
},

@@ -26,0 +27,0 @@ "devDependencies": {

@@ -5,6 +5,6 @@ var fs = require('fs'),

child_process = require('child_process');
exports.save = function(results, folder) {
exports.save = function(results, folder, callback) {
var tmpl = __dirname + "/junit.xml.ejs";
fs.readFile(tmpl, function (err, data) {

@@ -15,27 +15,31 @@ if (err) {

var tmpl = data.toString();
for (var moduleName in results.modules) {
var module = results.modules[moduleName];
var tests = 0, errors = 0, failures = 0;
for (var x in module) {
tests += module[x].passed + module[x].failed + module[x].skipped;
errors += module[x].errors;
failures += module[x].failed;
if (results.modules.hasOwnProperty(moduleName)) {
var module = results.modules[moduleName];
var tests = 0, errors = 0, failures = 0;
for (var x in module) {
if (module.hasOwnProperty(x)) {
tests += module[x].passed + module[x].failed + module[x].skipped;
errors += module[x].errors;
failures += module[x].failed;
}
}
var rendered = ejs.render(tmpl, {
locals: {
module : module,
moduleName : moduleName,
tests : tests,
errors : errors,
failures : failures,
systemerr : results.errmessages.join("\n")
}
});
var filename = path.join(folder, moduleName + '.xml');
fs.writeFile(filename, rendered, callback);
}
var rendered = ejs.render(tmpl, {
locals: {
module : module,
moduleName : moduleName,
tests : tests,
errors : errors,
failures : failures,
systemerr : results.errmessages.join("\n")
}
});
var filename = path.join(folder, moduleName + '.xml')
fs.writeFileSync(filename, rendered, 'utf8');
}
});
}
};

@@ -8,2 +8,3 @@ /**

var child_process = require('child_process');
var mkpath = require('mkpath');
var minimatch = require('minimatch');

@@ -127,3 +128,3 @@ var Nightwatch = require('../index.js');

function printResults(testresults) {
if (testresults.passed > 0 && testresults.errors == 0 && testresults.failed == 0) {
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.');

@@ -157,14 +158,2 @@ } else {

function ensureDir(path, callback) {
var mkdir = child_process.spawn('mkdir', ['-p', path]);
mkdir.on('error', function (err) {
callback(err);
callback = function(){};
});
mkdir.on('exit', function (code) {
if (code === 0) callback();
else callback(new Error('mkdir exited with code: ' + code));
});
}
function runFiles(paths, cb, opts) {

@@ -208,3 +197,3 @@ var extensionPattern = /\.js$/;

if (pending == 0) {
if (pending === 0) {
return done(null, results);

@@ -247,7 +236,7 @@ }

var curModule;
var paths;
finishCallback = finishCallback || function() {};
if (typeof files == 'string') {
var paths = [files];
paths = [files];
} else {

@@ -259,7 +248,7 @@ paths = files.map(function (p) {

if (paths.length == 0) {
if (paths.length === 0) {
throw new Error('No tests to run.');
}
runFiles(paths, function runTestModule(err, fullpaths) {
if (!fullpaths || fullpaths.length == 0) {
if (!fullpaths || fullpaths.length === 0) {
Logger.warn('No tests defined!');

@@ -270,5 +259,6 @@ console.log('using source folder', paths);

var module;
var modulePath = fullpaths.shift();
try {
var module = require(modulePath);
module = require(modulePath);
} catch (err) {

@@ -303,5 +293,17 @@ finishCallback(err);

} else {
ensureDir(output, function() {
Reporter.save(globalresults, output);
finishCallback(null);
mkpath(output, function(err) {
if (err) {
console.log(Logger.colors.yellow('Output folder doesn\'t exist and cannot be created.'));
console.log(err.stack);
finishCallback(null);
return;
}
Reporter.save(globalresults, output, function(err) {
if (err) {
console.log(Logger.colors.yellow('Warning: Failed to save report file to folder: ' + output));
console.log(err.stack);
}
finishCallback(null);
});
});

@@ -308,0 +310,0 @@ }

@@ -41,2 +41,5 @@ /**

}
if (test_settings.ie_driver) {
cliOpts.push('-Dwebdriver.ie.driver=' + test_settings.ie_driver);
}

@@ -43,0 +46,0 @@ seleniumProcess = spawn('java', cliOpts);

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