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.4.7 to 0.4.8

tests/sampletests/async/sample.js

23

bin/runner.js

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

var errorHandler = function(err) {
if (err) {
if (err.message) {
Logger.error(err.message);
} else {
Logger.error('There was an error while running the test.');
}
}
};
// running the tests
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) {

@@ -249,8 +258,5 @@ if (error) {

output_folder : output_folder,
src_folders : settings.src_folders,
selenium : (settings.selenium || null)
src_folders : settings.src_folders
}, function(err) {
if (err) {
console.log(Logger.colors.red('There was an error while running the test.'));
}
errorHandler(err);
selenium.stopServer();

@@ -261,4 +267,5 @@ });

runner.run(testsource, test_settings, {
output_folder : output_folder,
selenium : (settings.selenium || null)
output_folder : output_folder
}, function(err) {
errorHandler(err);
});

@@ -265,0 +272,0 @@ }

@@ -69,3 +69,8 @@ /*!

Nightwatch.prototype.setOptions = function(options) {
this.options = options || {};
this.options = {};
if (options && typeof options == 'object') {
for (var propName in options) {
this.options[propName] = options[propName];
}
}

@@ -76,7 +81,5 @@ this.api.launchUrl = this.options.launchUrl || this.options.launch_url || null;

if (this.options.globals) {
if (typeof this.options.globals == 'object') {
for (var globalKey in this.options.globals) {
this.api.globals[globalKey] = this.options.globals[globalKey];
}
if (this.options.globals && typeof this.options.globals == 'object') {
for (var globalKey in this.options.globals) {
this.api.globals[globalKey] = this.options.globals[globalKey];
}

@@ -135,3 +138,7 @@ }

Nightwatch.prototype.setCapabilities = function() {
this.desiredCapabilities = Nightwatch.DEFAULT_CAPABILITIES;
this.desiredCapabilities = {};
for (var capability in Nightwatch.DEFAULT_CAPABILITIES) {
this.desiredCapabilities[capability] = Nightwatch.DEFAULT_CAPABILITIES[capability];
}
if (this.options.desiredCapabilities) {

@@ -168,4 +175,3 @@ for (var prop in this.options.desiredCapabilities) {

Logger.info('FINISHED');
self.emit('queue:finished', self.results, self.errors);
self.printResult();
self.emit('nightwatch:finished', self.results, self.errors);
});

@@ -183,4 +189,3 @@ return this;

this.enqueueCommand('session', ['delete'], function(result) {
self.emit('queue:finished', self.results, self.errors);
self.printResult();
self.emit('nightwatch:finished', self.results, self.errors);
});

@@ -196,42 +201,41 @@

Nightwatch.prototype.printResult = function() {
if (!this.options.output) {
return;
}
var ok = false;
if (this.results.failed === 0 && this.results.errors === 0) {
ok = true;
}
if (this.options.output) {
var ok = false;
if (this.results.failed === 0 && this.results.errors === 0) {
ok = true;
}
if (ok && this.results.passed > 0) {
console.log(Logger.colors.green('OK.'),
Logger.colors.green(this.results.passed) + ' assertions passed.');
} else if (ok && this.results.passed === 0) {
console.log(Logger.colors.green('No assertions ran.'));
} else {
var errors = '';
if (this.results.errors) {
errors = this.results.errors + ' errors during the test. ';
for (var i = 0; i < this.errors.length; i++) {
console.log(Logger.colors.red(this.errors[i]));
if (ok && this.results.passed > 0) {
console.log(Logger.colors.green('OK.'),
Logger.colors.green(this.results.passed) + ' assertions passed.');
} else if (ok && this.results.passed === 0) {
console.log(Logger.colors.green('No assertions ran.'));
} else {
var errors = '';
if (this.results.errors) {
errors = this.results.errors + ' errors during the test. ';
for (var i = 0; i < this.errors.length; i++) {
console.log(Logger.colors.red(this.errors[i]));
}
}
var failure_msg = [];
if (this.results.failed > 0) {
failure_msg.push(Logger.colors.red(this.results.failed) +
' assertions failed');
}
if (this.results.errors > 0) {
failure_msg.push(Logger.colors.red(this.results.errors) + ' errors');
}
if (this.results.passed > 0) {
failure_msg.push(Logger.colors.green(this.results.passed) + ' passed');
}
if (this.results.skipped > 0) {
failure_msg.push(Logger.colors.blue(this.results.skipped) + ' skipped');
}
console.log(Logger.colors.red('FAILED: '), failure_msg.join(', ')
.replace(/,([^,]*)$/g, function($0, $1) {
return ' and' + $1;
}));
}
var failure_msg = [];
if (this.results.failed > 0) {
failure_msg.push(Logger.colors.red(this.results.failed) +
' assertions failed');
}
if (this.results.errors > 0) {
failure_msg.push(Logger.colors.red(this.results.errors) + ' errors');
}
if (this.results.passed > 0) {
failure_msg.push(Logger.colors.green(this.results.passed) + ' passed');
}
if (this.results.skipped > 0) {
failure_msg.push(Logger.colors.blue(this.results.skipped) + ' skipped');
}
console.log(Logger.colors.red('FAILED: '), failure_msg.join(', ')
.replace(/,([^,]*)$/g, function($0, $1) {
return ' and' + $1;
}));
}

@@ -276,2 +280,8 @@

self.saveScreenshotToFile(fileName, screenshotContent);
if (self.results.tests.length) {
var lastTest = self.results.tests[self.results.tests.length-1];
lastTest.screenshots = lastTest.screenshots || [];
lastTest.screenshots.push(fileName);
}
}

@@ -345,5 +355,5 @@

Nightwatch.prototype.startSession = function() {
Nightwatch.prototype.startSession = function () {
var self = this;
var request = new HttpRequest({
var options = {
path : '/session',

@@ -354,6 +364,7 @@ data : {

}
});
};
request.on('success', function(data, response) {
if (data.sessionId) {
var request = new HttpRequest(options);
request.on('success', function(data, response, isRedirect) {
if (data && data.sessionId) {
self.sessionId = self.api.sessionId = data.sessionId;

@@ -365,2 +376,4 @@ if (data.value) {

self.emit('selenium:session_create', self.sessionId, request, response);
} else if (isRedirect) {
self.followRedirect(request, response);
} else {

@@ -380,2 +393,19 @@ Logger.warn('Couldn\'t retrieve a new session from selenium server.');

Nightwatch.prototype.followRedirect = function (request, response) {
if (!response.headers || !response.headers.location) {
this.emit('error', null, null);
return this;
}
var url = require('url');
var urlParts = url.parse(response.headers.location);
request.setOptions({
path : urlParts.pathname,
host : urlParts.hostname,
port : urlParts.port,
method : 'GET'
}).send();
return this;
};
exports.client = function(options) {

@@ -382,0 +412,0 @@ return new Nightwatch(options);

@@ -23,2 +23,8 @@ var util = require('util'),

events.EventEmitter.call(this);
this.setOptions(options);
}
util.inherits(HttpRequest, events.EventEmitter);
HttpRequest.prototype.setOptions = function(options) {
this.data = options.data && JSON.stringify(options.data) || '';

@@ -28,9 +34,12 @@ this.contentLength = this.data.length;

this.request = null;
}
util.inherits(HttpRequest, events.EventEmitter);
return this;
};
HttpRequest.prototype.createOptions = function(options) {
var defaultPathPrefix = options.path && options.path.indexOf(Settings.default_path) === -1 ?
Settings.default_path : '';
var reqOptions = {
path : Settings.default_path + (options.path || ''),
path : defaultPathPrefix + (options.path || ''),
host : options.host || Settings.selenium_host,

@@ -42,3 +51,2 @@ port : options.selenium_port || Settings.selenium_port,

var requestMethod = reqOptions.method.toUpperCase();
if (options.sessionId) {

@@ -74,15 +82,5 @@ reqOptions.path = reqOptions.path.replace(':sessionId', options.sessionId);

response.setEncoding('utf8');
if (response.statusCode === 302 || response.statusCode === 304) {
Logger.info('Response ' + response.statusCode + ' ' + self.reqOptions.method + ' ' + self.reqOptions.path);
try {
self.emit('success', {}, response);
} catch (ex) {
console.log(ex.message);
console.log(ex.stack);
self.emit('error', {error:ex.message}, response);
}
self.emit('complete', response);
return self;
var redirected = false;
if (isRedirect(response.statusCode)) {
redirected = true;
}

@@ -99,3 +97,3 @@

var screenshotContent;
var data = '', result, errorMessage = '';
var result, errorMessage = '';
if (flushed) {

@@ -133,4 +131,4 @@ result = parseResult(flushed);

if (response.statusCode.toString().indexOf('2') === 0) {
self.emit('success', result, response);
if (response.statusCode.toString().indexOf('2') === 0 || redirected) {
self.emit('success', result, response, redirected);
} else {

@@ -173,2 +171,6 @@ self.emit('error', result, response, screenshotContent);

///////////////////////////////////////////////////////////
function isRedirect(statusCode) {
return [302, 303, 304].indexOf(statusCode) > -1;
}
function needsContentLengthHeader(requestMethod) {

@@ -175,0 +177,0 @@ return ['POST', 'DELETE'].indexOf(requestMethod) > -1;

@@ -63,7 +63,19 @@ module.exports = function(Nightwatch) {

* @link /session/:sessionId/timeouts
* @param {string} type The type of operation to set the timeout for. Valid values are: "script" for script timeouts, "implicit" for modifying the implicit wait timeout and "page load" for setting a page load timeout.
* @param {number} ms The amount of time, in milliseconds, that time-limited commands are permitted to run.
* @param {function} [callback] Optional callback function to be called when the command finishes.
* @api protocol
*/
Actions.timeouts = function(callback) {
return postRequest('/timeouts', callback);
Actions.timeouts = function(type, ms, callback) {
var timeoutValues = ['script', 'implicit', 'page load'];
if (timeoutValues.indexOf(type) === -1) {
throw new Error('Invalid timeouts type value: ' + type + '. Possible values are: ' + timeoutValues.join(','));
}
if (typeof ms != 'number') {
throw new Error('Second argument must be number.');
}
return postRequest('/timeouts', {
type : type,
ms : ms
}, callback);
};

@@ -75,7 +87,13 @@

* @link /session/:sessionId/timeouts/async_script
* @param {number} ms The amount of time, in milliseconds, that time-limited commands are permitted to run.
* @param {function} [callback] Optional callback function to be called when the command finishes.
* @api protocol
*/
Actions.timeoutsAsyncScript = function(callback) {
return postRequest('/timeouts/async_script', callback);
Actions.timeoutsAsyncScript = function(ms, callback) {
if (typeof ms != 'number') {
throw new Error('First argument must be number.');
}
return postRequest('/timeouts/async_script', {
ms : ms
}, callback);
};

@@ -87,7 +105,13 @@

* @link /session/:sessionId/timeouts/implicit_wait
* @param {number} ms The amount of time, in milliseconds, that time-limited commands are permitted to run.
* @param {function} [callback] Optional callback function to be called when the command finishes.
* @api protocol
*/
Actions.timeoutsImplicitWait = function(callback) {
return postRequest('/timeouts/implicit_wait', callback);
Actions.timeoutsImplicitWait = function(ms, callback) {
if (typeof ms != 'number') {
throw new Error('First argument must be number.');
}
return postRequest('/timeouts/implicit_wait', {
ms : ms
}, callback);
};

@@ -476,3 +500,5 @@

if ((arguments.length === 3) && (typeof arguments[2] === 'function')) {
if (arguments.length === 2) {
args = [];
} else if ((arguments.length === 3) && (typeof arguments[2] === 'function')) {
callback = arguments[2];

@@ -513,6 +539,6 @@ args = [];

Actions.execute = function(body, args, callback) {
args = Array.prototype.slice.call(arguments, 0);
args.unshift('/execute');
var executeArgs = Array.prototype.slice.call(arguments, 0);
executeArgs.unshift('/execute');
return executeHandler.apply(null, args);
return executeHandler.apply(null, executeArgs);
};

@@ -575,2 +601,12 @@

/**
* Change focus to the parent context. If the current context is the top level browsing context, the context remains unchanged.
*
* @param callback
* @returns {*}
*/
Actions.frameParent = function(callback) {
return postRequest('/frame/parent', callback);
};
/**
* Change focus to another window or close the current window.

@@ -577,0 +613,0 @@ *

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

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

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

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

@@ -13,3 +12,2 @@ var minimatch = require('minimatch');

var Logger = require('../lib/logger.js');
var Reporter = require('./reporters/junit.js');

@@ -27,3 +25,3 @@ module.exports = new (function() {

function runModule(module, opts, moduleName, callback, finishCallback) {
function runModule(module, opts, moduleName, moduleCallback, finishCallback) {
var client;

@@ -37,51 +35,55 @@ try {

}
var keys = Object.keys(module);
var keys = Object.keys(module);
var currentTest;
var setUp;
var tearDown;
var testResults = {
passed : 0,
failed : 0,
errors : 0,
passed : 0,
failed : 0,
errors : 0,
skipped : 0,
tests : 0,
steps : keys.slice(0)
tests : 0,
steps : keys.slice(0)
};
module.client = client.api;
var onTestFinished = function (results, errors) {
globalResults.modules[moduleName][currentTest] = {
passed : results.passed,
failed : results.failed,
errors : results.errors,
skipped : results.skipped,
tests : [].concat(results.tests)
};
if (module.disabled === true) {
console.log('\nSkipping module: ', Logger.colors.cyan(moduleName));
callback(null, false);
return;
}
if (Array.isArray(errors) && errors.length) {
globalResults.errmessages = globalResults.errmessages.concat(errors);
}
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(cb) {
cb();
};
}
testResults.passed += results.passed;
testResults.failed += results.failed;
testResults.errors += results.errors;
testResults.skipped += results.skipped;
testResults.tests += results.tests.length;
if (keys.indexOf('tearDown') > -1) {
tearDown = function(clientFn) {
module.tearDown(client.api);
clientFn();
};
keys.splice(keys.indexOf('tearDown'), 1);
testResults.steps.splice(testResults.steps.indexOf('tearDown'), 1);
client.printResult();
} else {
tearDown = function(callback) {callback();};
}
if (client.terminated) {
moduleCallback(null, testResults, keys);
} else {
setTimeout(next, 0);
}
};
function next() {
var startClient = function(context, clientFn, client, onComplete) {
client.once('nightwatch:finished', function(results, errors) {
onComplete(results, errors);
});
clientFn.call(context, context.client);
client.start();
};
var next = function() {
if (keys.length) {
var key = keys.shift();
if (typeof module[key] != 'function') {
currentTest = keys.shift();
if (typeof module[currentTest] != 'function') {
next();

@@ -91,28 +93,7 @@ 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)
};
if (opts.output) {
console.log('\nRunning: ', Logger.colors.green(currentTest));
}
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 (client.terminated) {
callback(null, testResults, keys);
} else {
setTimeout(next, 0);
}
}, client);
var test = wrapTest(setUp, tearDown, module[currentTest], module, onTestFinished, client);
var error = false;

@@ -128,14 +109,61 @@ try {

error = true;
callback(err, testResults);
moduleCallback(err, testResults);
}
} else {
moduleCallback(null, testResults);
}
};
if (!error) {
client.start();
}
module.client = client.api;
} else {
callback(null, testResults);
if (module.disabled === true) {
if (opts.output) {
console.log('\nSkipping module: ', Logger.colors.cyan(moduleName));
}
moduleCallback(null, false);
return;
}
// handling asynchronous setUp/tearDown case:
// 1) if setUp/tearDown is defined with only one arg run it synchronously
// 2) if setUp/tearDown is defined with two args, assume the second one to be the callback
// and pass the callbackFn as the second arg to be called from the async operation
if (keys.indexOf('setUp') > -1) {
setUp = function(context, clientFn) {
if (module.setUp.length <= 1) {
module.setUp.call(context, context.client);
clientFn();
} else if (module.setUp.length >= 1) {
module.setUp.call(context, context.client, clientFn);
}
};
keys.splice(keys.indexOf('setUp'), 1);
testResults.steps.splice(testResults.steps.indexOf('setUp'), 1);
} else {
setUp = function(context, cb) {
cb();
};
}
if (typeof module.tearDown == 'function') {
tearDown = function(context, clientFn, client, onTestComplete) {
if (module.tearDown.length === 0) {
startClient(context, clientFn, client, function(results, errors) {
module.tearDown();
onTestComplete(results, errors);
});
} else if (module.tearDown.length >= 0) {
startClient(context, clientFn, client, function(results, errors) {
module.tearDown(function() {
onTestComplete(results, errors);
});
});
}
};
keys.splice(keys.indexOf('tearDown'), 1);
testResults.steps.splice(testResults.steps.indexOf('tearDown'), 1);
} else {
tearDown = startClient;
}
setTimeout(next, 0);

@@ -160,3 +188,3 @@ }

console.log(Logger.colors.light_red('\nTEST FAILURE:'), Logger.colors.red(testresults.errors + testresults.failed) +
' assertions failed, ' + Logger.colors.green(testresults.passed) + ' passed' + skipped);
' assertions failed, ' + Logger.colors.green(testresults.passed) + ' passed' + skipped);
}

@@ -175,16 +203,11 @@ }

function wrapTest(setUp, tearDown, fn, context, onComplete, client) {
return function (c) {
context.client = c;
var clientFn = function () {
client.once('queue:finished', function(results, errors) {
tearDown.call(context, function() {
onComplete.call(context, results, errors);
});
});
function wrapTest(setUp, tearDown, testFn, context, onComplete, client) {
return function (api) {
context.client = api;
return fn.call(context, c);
var clientFn = function() {
return tearDown(context, testFn, client, onComplete);
};
setUp.call(context, clientFn);
setUp(context, clientFn);
};

@@ -296,7 +319,3 @@ }

this.run = function runner(files, opts, aditional_opts, finishCallback) {
var start = new Date().getTime();
var modules = {};
var curModule;
var paths;
finishCallback = finishCallback || function() {};

@@ -308,2 +327,5 @@

paths = files.map(function (p) {
if (p.indexOf(process.cwd()) === 0) {
return p;
}
return path.join(process.cwd(), p);

@@ -316,7 +338,5 @@ });

}
runFiles(paths, function runTestModule(err, fullpaths) {
if (!fullpaths || fullpaths.length === 0) {
Logger.warn('No tests defined!');
console.log('using source folder', paths);
finishCallback({message: 'No tests defined! using source folder ' + paths});
return;

@@ -330,3 +350,3 @@ }

} catch (err) {
finishCallback(err, false);
finishCallback(err);
throw err;

@@ -337,4 +357,5 @@ }

globalResults.modules[moduleName] = [];
console.log('\n' + Logger.colors.cyan('[ ' + moduleName + ' module ]'));
if (opts.output) {
console.log('\n' + Logger.colors.cyan('[ ' + moduleName + ' module ]'));
}
runModule(module, opts, moduleName, function(err, testresults, modulekeys) {

@@ -349,3 +370,2 @@ if (typeof testresults == 'object') {

if (fullpaths.length) {

@@ -356,12 +376,11 @@ setTimeout(function() {

} else {
if (testresults.tests != globalResults.tests || testresults.steps.length > 1) {
if (opts.output && testresults.tests != globalResults.tests || testresults.steps.length > 1) {
printResults(globalResults, modulekeys);
}
var diffInFolder = getPathDiff(modulePath, aditional_opts);
var output = path.join(aditional_opts.output_folder, diffInFolder);
var success = globalResults.failed === 0 && globalResults.errors === 0;
if (output === false) {
finishCallback(null, success);
if (aditional_opts.output_folder === false) {
finishCallback(null, globalResults, modulekeys);
} else {
var diffInFolder = getPathDiff(modulePath, aditional_opts);
var output = path.join(aditional_opts.output_folder, diffInFolder);
mkpath(output, function(err) {

@@ -371,6 +390,7 @@ if (err) {

console.log(err.stack);
finishCallback(null, success);
finishCallback(null);
return;
}
var Reporter = require('./reporters/junit.js');
Reporter.save(globalResults, output, function(err) {

@@ -381,3 +401,3 @@ if (err) {

}
finishCallback(null, success);
finishCallback(null);
});

@@ -393,2 +413,1 @@ });

})();

@@ -10,7 +10,24 @@ {

},
"statusCode" : 200,
"statusCode" : 201,
"method": "POST"
},
{
"url" : "/wd/hub/session",
"postdata" : "{\"desiredCapabilities\":{\"browserName\":\"chrome\",\"javascriptEnabled\":true,\"acceptSslCerts\":true,\"platform\":\"ANY\"},\"sessionId\":null}",
"responseHeaders" : {
"location" : "http://localhost:10195/wd/hub/session/1352110219202"
},
"statusCode" : 302,
"method": "POST"
},
{
"url" : "/wd/hub/session/1352110219202",
"response" : "{\"status\": 0, \"sessionId\": \"1352110219202\", \"value\": { \"javascriptEnabled\": true, \"browserName\": \"chrome\"}, \"state\": null}",
"responseHeaders" : {
},
"statusCode" : 201,
"method": "GET"
},
{
"url" : "/wd/hub/session/1352110219202",
"method": "DELETE"

@@ -20,3 +37,3 @@ },

"url" : "/wd/hub/session/1352110219202/url",
"postdata" : "{\"url\":\"http://localhost\"}"
"postdata" : "{\"url\":\"http://localhost\"}"
},

@@ -61,2 +78,2 @@ {

]
}
}
var nightwatch = require('../index.js');
module.exports = {
init : function(callback) {
return nightwatch.client({
init : function(options, callback) {
var opts = {
seleniumPort : 10195,

@@ -12,3 +12,11 @@ silent : true,

}
}).start().once('error', function() {
};
if (options) {
for (var prop in options) {
opts[prop] = options[prop];
}
}
return nightwatch.client(opts).start().once('error', function() {
if (callback) {

@@ -15,0 +23,0 @@ callback();

@@ -28,9 +28,6 @@ try {

server.on('listening', function() {
reporter.run(['src', 'src/assertions', 'src/protocol', 'src/commands'], options, function() {
reporter.run(['src', 'src/index', 'src/assertions', 'src/protocol', 'src/commands'], options, function() {
server.close();
});
});
//reporter.run(['src/commands'], options);
} catch (err) {

@@ -37,0 +34,0 @@ console.log(e);

@@ -5,3 +5,3 @@ var CommandQueue = require('../../lib/queue.js');

setUp: function (callback) {
this.client = require('../nightwatch.js').init(callback);
this.client = require('../nightwatch.js').init({}, callback);

@@ -8,0 +8,0 @@ callback();

@@ -0,4 +1,6 @@

var Client = require('../nightwatch.js');
module.exports = {
setUp: function (callback) {
this.client = require('../nightwatch.js').init();
this.client = null;
callback();

@@ -9,5 +11,6 @@ },

var self = this;
this.client = Client.init();
this.client.on('selenium:session_create', function(sessionId) {
test.equal(self.client.sessionId, 1352110219202, 'Testing if session ID was set correctly');
test.equal(self.client.api.capabilities.browserName, 'firefox');
test.done();

@@ -18,4 +21,5 @@ });

'Test runProtocolCommand without error' : function(test) {
var client = this.client;
this.client.on('selenium:session_create', function(sessionId) {
var client = this.client = Client.init();
client.on('selenium:session_create', function(sessionId) {
var request = client.runProtocolAction({

@@ -39,8 +43,7 @@ host : '127.0.0.1',

'Test runProtocolAction with error' : function(test) {
var client = this.client;
var client = this.client = Client.init();
this.client.saveScreenshotToFile = function() {};
this.client.options.screenshots.enabled = true;
this.client.on('selenium:session_create', function(sessionId) {
client.saveScreenshotToFile = function() {};
client.options.screenshots.enabled = true;
client.on('selenium:session_create', function(sessionId) {
var request = client.runProtocolAction({

@@ -64,3 +67,4 @@ host : '127.0.0.1',

testRunCommand : function(test) {
var client = this.client;
var client = this.client = Client.init();
client.enqueueCommand('url', ['http://localhost'], function(result) {

@@ -72,2 +76,16 @@ test.ok(true, 'Callback 1 was called');

testChromeSessionWithRedirectStatus : function(test) {
var client = this.client = Client.init({
desiredCapabilities: {
browserName : 'chrome'
}
});
test.expect(2);
client.on('selenium:session_create', function(sessionId) {
test.equal(sessionId, 1352110219202);
test.equal(client.api.capabilities.browserName, 'chrome');
test.done();
});
},
tearDown : function(callback) {

@@ -74,0 +92,0 @@ this.client.queue.reset();

@@ -11,3 +11,2 @@ module.exports = {

var protocol = this.protocol;
this.client.on('selenium:session_create', function(sessionId) {

@@ -55,3 +54,2 @@ var command = protocol.element('id', '#weblogin', function callback() {

testElementIdClear : function(test) {
var client = this.client;
var protocol = this.protocol;

@@ -297,2 +295,17 @@

testExecuteFunctionNoArgs : function(test) {
var client = this.client;
var protocol = this.protocol;
this.client.on('selenium:session_create', function(sessionId) {
var command = protocol.execute(function() {return test();})
.on('complete', function() {
test.done();
});
test.equal(command.data, '{"script":"var passedArgs = Array.prototype.slice.call(arguments,0); ' +
'return function () {return test();}.apply(window, passedArgs);","args":[]}');
});
},
testExecuteAsync : function(test) {

@@ -357,2 +370,16 @@ var client = this.client;

testFrameParent : function(test) {
var client = this.client;
var protocol = this.protocol;
this.client.on('selenium:session_create', function(sessionId) {
var command = protocol.frameParent(function callback() {
test.done();
});
test.equal(command.request.method, 'POST');
test.equal(command.request.path, '/wd/hub/session/1352110219202/frame/parent');
});
},
'test mouseButtonDown click left' : function(test) {

@@ -759,2 +786,63 @@ var client = this.client;

testTimeoutsValid : function(test) {
var protocol = this.protocol;
this.client.on('selenium:session_create', function() {
var command = protocol.timeouts('script', 1000, function callback() {
test.done();
});
test.equal(command.request.method, 'POST');
test.equal(command.data, '{"type":"script","ms":1000}');
test.equal(command.request.path, '/wd/hub/session/1352110219202/timeouts');
});
},
testTimeoutsInvalid : function(test) {
var protocol = this.protocol;
this.client.on('selenium:session_create', function() {
test.throws(
function() {
protocol.timeouts('nonscript', 1000);
}
);
test.throws(
function() {
test.done();
protocol.timeouts('script');
}
);
});
},
testTimeoutsAsyncScript : function(test) {
var protocol = this.protocol;
this.client.on('selenium:session_create', function() {
var command = protocol.timeoutsAsyncScript(1000, function callback() {
test.done();
});
test.equal(command.request.method, 'POST');
test.equal(command.data, '{"ms":1000}');
test.equal(command.request.path, '/wd/hub/session/1352110219202/timeouts/async_script');
});
},
testTimeoutsImplicitWait : function(test) {
var protocol = this.protocol;
this.client.on('selenium:session_create', function() {
var command = protocol.timeoutsImplicitWait(1000, function callback() {
test.done();
});
test.equal(command.request.method, 'POST');
test.equal(command.data, '{"ms":1000}');
test.equal(command.request.path, '/wd/hub/session/1352110219202/timeouts/implicit_wait');
});
},
tearDown : function(callback) {

@@ -761,0 +849,0 @@ this.client = null;

@@ -13,3 +13,3 @@ var CommandQueue = require('../../lib/queue.js');

var client = this.client, urlCommand, endCommand;
this.client.on('queue:finished', function() {
this.client.on('nightwatch:finished', function() {
test.equal(true, urlCommand.done);

@@ -16,0 +16,0 @@ test.equal(true, endCommand.children[0].done);

Sorry, the diff of this file is not supported yet

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