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.5.11 to 0.5.12

tests/extra/assertions/customAssertion.js

19

bin/_clirunner.js

@@ -8,2 +8,3 @@ var Runner = require('../lib/runner/run.js');

var SETTINGS_DEPRECTED_VAL = './settings.json';
var SETTINGS_JS_FILE = './nightwatch.conf.js';

@@ -37,8 +38,10 @@ function CliRunner(argv) {

var defaultValue = this.cli.command('config').defaults();
var deprecatedValue = SETTINGS_DEPRECTED_VAL;
var localJsValue = path.resolve(SETTINGS_JS_FILE);
if (fs.existsSync(defaultValue)) {
if (fs.existsSync(SETTINGS_JS_FILE)) {
this.argv.c = localJsValue;
} else if (fs.existsSync(defaultValue)) {
this.argv.c = path.join(path.resolve('./'), this.argv.c);
} else if (fs.existsSync(deprecatedValue)) {
this.argv.c = path.join(path.resolve('./'), deprecatedValue);
} else if (fs.existsSync(SETTINGS_DEPRECTED_VAL)) {
this.argv.c = path.join(path.resolve('./'), SETTINGS_DEPRECTED_VAL);
} else {

@@ -49,3 +52,3 @@ var defaultFile = path.join(__dirname, this.argv.c);

} else {
this.argv.c = path.join(__dirname, deprecatedValue);
this.argv.c = path.join(__dirname, SETTINGS_DEPRECTED_VAL);
}

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

if (this.test_settings.output) {
console.log(Logger.colors.red(err.message));
process.stderr.write('\n' + Logger.colors.red(err.message));
}
process.exit(1);

@@ -321,2 +325,3 @@ }

this.test_settings.custom_assertions_path = this.settings.custom_assertions_path || '';
this.test_settings.page_objects_path = this.settings.page_objects_path || '';

@@ -506,3 +511,3 @@ this.inheritFromDefaultEnv();

var env = process.env;
setTimeout(function() {

@@ -509,0 +514,0 @@ env.__NIGHTWATCH_PARALLEL_MODE = 1;

@@ -6,3 +6,3 @@ {

"custom_assertions_path" : "",
"globals_path" : "./examples/globals.json",
"globals_path" : "",
"live_output" : false,

@@ -9,0 +9,0 @@

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

console.log(ex.stack);
process.exit(2);
}

@@ -17,2 +17,3 @@ /*!

var custom_assertions_path;
var page_objects_path;

@@ -31,5 +32,5 @@ /////////////////////////////////////////////////////////////////////

return function() {
var passed, expected = null;
var actual = arguments[0];
var passed;
var expected;
var actual;
var lastArgument = arguments[arguments.length-1];

@@ -40,3 +41,3 @@ var isLastArgString = typeof lastArgument === 'string';

lastArgument || (typeof arguments[0] === 'function' && '[Function]') ||
'' + actual;
('' + actual);

@@ -281,2 +282,63 @@ try {

/**
* Loads page object files
*/
function loadPageObjects() {
if (!page_objects_path) {
return;
}
client.api.page = {};
var absPath = path.join(process.cwd(), page_objects_path);
var pageFiles = fs.readdirSync(absPath);
for (var i = 0, len = pageFiles.length; i < len; i++) {
if (path.extname(pageFiles[i]) === '.js') {
var pageName = path.basename(pageFiles[i], '.js');
var pageFnOrObject = require(path.join(absPath, pageFiles[i]));
addPageObject(pageName, pageFnOrObject, client.api, client.api.page);
}
}
}
/**
* Instantiates the page object class
* @param {String} name
* @param {Object} pageFnOrObject
* @param {Object} context
* @param {Object} parent
*/
function addPageObject(name, pageFnOrObject, context, parent) {
parent[name] = function() {
var args = Array.prototype.slice.call(arguments);
args.unshift(context);
return new (function() {
if (typeof pageFnOrObject == 'function') {
if (!pageFnOrObject.prototype._instance) {
pageFnOrObject.prototype._instance = createPageObject(pageFnOrObject, args);
}
return pageFnOrObject.prototype._instance;
}
return pageFnOrObject;
})();
};
}
/**
*
* @param pageFnOrObject
* @param args
* @returns {Object}
*/
function createPageObject(pageFnOrObject, args) {
function PageObject() {
return pageFnOrObject.apply(this, args);
}
PageObject.prototype = pageFnOrObject.prototype;
return new PageObject();
}
/**
* Adds a command/assertion to the queue.

@@ -288,5 +350,4 @@ *

* @param {Object} [parent]
* @param {Boolean} [resetQueue]
*/
function addCommand(name, command, context, parent, resetQueue) {
function addCommand(name, command, context, parent) {
parent = parent || client.api;

@@ -316,2 +377,3 @@ if (parent[name]) {

custom_assertions_path = c.options.custom_assertions_path;
page_objects_path = c.options.page_objects_path;
return this;

@@ -329,2 +391,3 @@ };

loadCustomAssertions();
loadPageObjects();
return this;

@@ -336,3 +399,4 @@ };

this.loadCustomAssertions = loadCustomAssertions;
this.loadPageObjects = loadPageObjects;
this.createAssertion = createAssertion;
})();

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

'Unable to locate element',
'{"errorMessage":"Unable to find element',
'no such element'

@@ -20,0 +21,0 @@ ];

@@ -292,11 +292,9 @@ /*!

.on('result', function(result) {
if (callback) {
if (typeof callback != 'function') {
var error = new Error('Callback parameter is not a function - ' + typeof(callback) + ' passed: "' + callback + '"');
self.errors.push(error.stack);
self.results.errors++;
} else {
try {
if (typeof callback != 'function') {
var error = new Error('Callback parameter is not a function - ' + typeof(callback) + ' passed: "' + callback + '"');
self.errors.push(error.stack);
self.results.errors++;
} else {
callback.call(self.api, result);
}
callback.call(self.api, result);
} catch (ex) {

@@ -306,15 +304,15 @@ self.errors.push('Error while running tests: ' + ex.message);

var firstLine = stack.shift();
console.log(' ' + Logger.colors.light_green(firstLine));
console.log(' ' + Logger.colors.red(firstLine));
console.log(stack.join('\n'));
self.results.errors++;
}
}
if (result.lastScreenshotFile && self.results.tests.length > 0) {
var lastTest = self.results.tests[self.results.tests.length-1];
lastTest.screenshots = lastTest.screenshots || [];
lastTest.screenshots.push(result.lastScreenshotFile);
delete result.lastScreenshotFile;
}
if (result.lastScreenshotFile && self.results.tests.length > 0) {
var lastTest = self.results.tests[self.results.tests.length-1];
lastTest.screenshots = lastTest.screenshots || [];
lastTest.screenshots.push(result.lastScreenshotFile);
delete result.lastScreenshotFile;
}
});

@@ -321,0 +319,0 @@

@@ -1,50 +0,78 @@

var fs = require('fs'),
mkpath = require('mkpath'),
path = require('path'),
ejs = require('ejs');
var fs = require('fs');
var mkpath = require('mkpath');
var path = require('path');
var ejs = require('ejs');
exports.save = function(results, opts, callback) {
module.exports = new (function() {
var tmpl = __dirname + '/junit.xml.ejs';
var tmplData;
var globalResults;
fs.readFile(tmpl, function (err, data) {
if (err) {
throw err;
function loadTemplate(cb) {
if (tmplData) {
cb(tmplData);
return;
}
var tmpl = data.toString();
fs.readFile(tmpl, function (err, data) {
if (err) {
throw err;
}
tmplData = data.toString();
cb(tmplData);
});
}
for (var moduleKey in results.modules) {
if (results.modules.hasOwnProperty(moduleKey)) {
var module = results.modules[moduleKey];
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 pathParts = moduleKey.split(path.sep);
var moduleName = pathParts.pop();
var rendered = ejs.render(tmpl, {
locals: {
module : module,
moduleName : moduleName,
testsNo : tests,
errors : errors,
failures : failures,
systemerr : results.errmessages.join('\n')
}
});
function writeReport(moduleKey, opts, callback) {
var module = globalResults.modules[moduleKey];
var tests = 0, errors = 0, failures = 0;
var pathParts = moduleKey.split(path.sep);
var moduleName = pathParts.pop();
var output_folder = opts.output_folder;
var output_folder = opts.output_folder;
if (pathParts.length) {
output_folder = path.join(output_folder, pathParts.join(path.sep));
mkpath.sync(output_folder);
}
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 filename = path.join(output_folder, opts.filename_prefix + moduleName + '.xml');
fs.writeFile(filename, rendered, callback);
var rendered = ejs.render(tmpl, {
locals: {
module : module,
moduleName : moduleName,
testsNo : tests,
errors : errors,
failures : failures,
systemerr : globalResults.errmessages.join('\n')
}
});
if (pathParts.length) {
output_folder = path.join(output_folder, pathParts.join(path.sep));
mkpath.sync(output_folder);
}
});
};
var filename = path.join(output_folder, opts.filename_prefix + moduleName + '.xml');
fs.writeFile(filename, rendered, callback);
}
this.save = function(results, options, callback) {
globalResults = results;
var keys = Object.keys(results.modules);
loadTemplate(function createReport() {
var moduleKey = keys.shift();
writeReport(moduleKey, options, function(err) {
if (err || (keys.length === 0)) {
callback(err);
} else {
createReport();
}
});
});
};
})();

@@ -94,2 +94,7 @@ /**

currentTest = keys.shift();
client.api.currentTest = {
name : currentTest,
module : moduleKey.replace(path.sep , '/')
};
if (typeof module[currentTest] != 'function') {

@@ -238,2 +243,3 @@ testResults.steps.splice(testResults.steps.indexOf(currentTest), 1);

}
console.log(Logger.colors.light_red('\nTEST FAILURE:'), errorsMsg + Logger.colors.red(testresults.failed) +

@@ -250,2 +256,3 @@ ' assertions failed, ' + Logger.colors.green(testresults.passed) + ' passed' + skipped + '.', '(' + elapsedTime + ' ms)');

}
process.exit(exitCode);

@@ -422,3 +429,2 @@ });

opts.live_output = additional_opts.live_output;
opts.report_prefix = '';

@@ -478,7 +484,7 @@

}
runModule(module, opts, moduleName, moduleKey, function(err, modulekeys) {
runModule(module, opts, moduleName, moduleKey, function moduleCallback(err, modulekeys) {
if (fullpaths.length) {
setTimeout(function() {
runTestModule(err, fullpaths);
}, 0);
}, 1000);
} else {

@@ -509,5 +515,4 @@ if (opts.output) {

}
finishCallback(null, globalResults);
});
finishCallback(null);
});

@@ -514,0 +519,0 @@ }

@@ -375,5 +375,5 @@ module.exports = function(client) {

return this.execute(function(u,i) {/* jshint browser:true */return (function(d){var e=d.createElement('script');var m=d.getElementsByTagName('script')[0];e.src=u;if(i){e.id=i;}m.parentNode.insertBefore(e,m);return e;})(document);}, args, callback);
return this.execute(function(u,i) {/* jshint browser:true */return (function(d){var e=d.createElement('script');var m=d.getElementsByTagName('head')[0];e.src=u;if(i){e.id=i;}m.appendChild(e);return e;})(document);}, args, callback);
}
};
};
{
"name": "nightwatch",
"description": "A node.js bindings implementation for selenium 2.0/webdriver",
"version": "0.5.11",
"version": "0.5.12",
"author": {

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

@@ -24,8 +24,10 @@ try {

process.chdir(__dirname);
try {
var server = require('mockserver').init();
server.on('listening', function() {
reporter.run(['src', 'src/index', 'src/runner', 'src/assertions', 'src/commands'], options, function() {
reporter.run(['src', 'src/index', 'src/runner', 'src/assertions', 'src/commands'], options, function(err) {
server.close();
if (err) {
process.exit(1);
}
});

@@ -35,3 +37,3 @@ });

console.log(err.stack);
process.exit();
process.exit(1);
}

@@ -33,2 +33,4 @@ var BASE_PATH = process.env.NIGHTWATCH_COV

mockery.registerMock('./nightwatch.json', config);
mockery.registerMock('./nightwatch.conf.js', config);
mockery.registerMock('./output_disabled.json', {

@@ -159,2 +161,3 @@ src_folders : ['tests'],

custom_assertions_path: '',
page_objects_path: '',
output: true

@@ -173,5 +176,6 @@ }});

existsSync : function(module) {
if (module == './settings.json') {
if (module == './settings.json' || module == './nightwatch.conf.js') {
return false;
}
return true;

@@ -178,0 +182,0 @@ }

@@ -47,3 +47,3 @@ var BASE_PATH = process.env.NIGHTWATCH_COV ? 'lib-cov' : 'lib';

client.options.custom_commands_path = './extra';
client.options.custom_commands_path = './extra/commands';
Api.init(client);

@@ -61,2 +61,36 @@ Api.loadCustomCommands();

testAddPageObject : function(test) {
var client = this.client;
client.on('selenium:session_create', function(sessionId) {
test.done();
});
client.options.page_objects_path = './extra/pageobjects';
Api.init(client);
Api.loadPageObjects();
test.ok(typeof client.api.page == 'object');
test.ok('SimplePage' in client.api.page);
client.api.page.SimplePage(test);
},
testAddCustomAssertion : function(test) {
var client = this.client;
client.on('selenium:session_create', function(sessionId) {
test.done();
});
client.options.custom_assertions_path = './extra/assertions';
Api.init(client);
Api.loadCustomAssertions();
test.expect(4);
test.ok('customAssertion' in client.api.assert);
test.ok('customAssertion' in client.api.verify);
client.api.assert.customAssertion(test, true);
client.queue.run();
},
tearDown : function(callback) {

@@ -63,0 +97,0 @@

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