refactor app directory structure and add tests
This commit is contained in:
24
tests/node_modules/nightwatch/lib/api/client-commands/_locateStrategy.js
generated
vendored
Normal file
24
tests/node_modules/nightwatch/lib/api/client-commands/_locateStrategy.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
var util = require('util');
|
||||
var events = require('events');
|
||||
|
||||
function Command() {
|
||||
events.EventEmitter.call(this);
|
||||
}
|
||||
|
||||
util.inherits(Command, events.EventEmitter);
|
||||
|
||||
Command.prototype.command = function(callback) {
|
||||
var self = this;
|
||||
|
||||
this.client.locateStrategy = this.strategy;
|
||||
process.nextTick(function() {
|
||||
if (typeof callback == 'function') {
|
||||
callback.call(self.client.api);
|
||||
}
|
||||
self.emit('complete');
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
module.exports = Command;
|
70
tests/node_modules/nightwatch/lib/api/client-commands/end.js
generated
vendored
Normal file
70
tests/node_modules/nightwatch/lib/api/client-commands/end.js
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
var util = require('util');
|
||||
var events = require('events');
|
||||
var Utils = require('../../util/utils.js');
|
||||
var Logger = require('../../util/logger.js');
|
||||
|
||||
/**
|
||||
* Ends the session. Uses session protocol command.
|
||||
*
|
||||
* ```
|
||||
* this.demoTest = function (browser) {
|
||||
* browser.end();
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* @method end
|
||||
* @param {function} [callback] Optional callback function to be called when the command finishes.
|
||||
* @see session
|
||||
* @api commands
|
||||
*/
|
||||
function End() {
|
||||
events.EventEmitter.call(this);
|
||||
}
|
||||
|
||||
util.inherits(End, events.EventEmitter);
|
||||
|
||||
End.prototype.command = function(callback) {
|
||||
var self = this;
|
||||
var client = this.client;
|
||||
|
||||
if (client.sessionId) {
|
||||
if (this.testFailuresExist() && this.shouldTakeScreenshot()) {
|
||||
var fileNamePath = Utils.getScreenshotFileName(client.api.currentTest, false, client.options.screenshots.path);
|
||||
Logger.info('We have failures in "' + client.api.currentTest.name + '". Taking screenshot...');
|
||||
|
||||
client.api.saveScreenshot(fileNamePath, function(result, err) {
|
||||
if (err || result.status !== 0) {
|
||||
Logger.warn('Error saving screenshot...', err || result);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
client.api.session('delete', function(result) {
|
||||
client.sessionId = client.api.sessionId = null;
|
||||
self.complete(callback, result);
|
||||
});
|
||||
} else {
|
||||
setImmediate(function() {
|
||||
self.complete(callback, null);
|
||||
});
|
||||
}
|
||||
|
||||
return this.client.api;
|
||||
};
|
||||
|
||||
End.prototype.testFailuresExist = function() {
|
||||
return this.client.results.errors > 0 || this.client.results.failed > 0;
|
||||
};
|
||||
|
||||
End.prototype.shouldTakeScreenshot = function() {
|
||||
return this.client.options.screenshots.enabled && this.client.options.screenshots.on_failure;
|
||||
};
|
||||
|
||||
End.prototype.complete = function(callback, result) {
|
||||
if (typeof callback === 'function') {
|
||||
callback.call(this, result);
|
||||
}
|
||||
this.emit('complete');
|
||||
};
|
||||
|
||||
module.exports = End;
|
46
tests/node_modules/nightwatch/lib/api/client-commands/pause.js
generated
vendored
Normal file
46
tests/node_modules/nightwatch/lib/api/client-commands/pause.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
var util = require('util');
|
||||
var events = require('events');
|
||||
|
||||
/**
|
||||
* Suspends the test for the given time in milliseconds. If the milliseconds argument is missing it will suspend the test indefinitely
|
||||
*
|
||||
* ```
|
||||
* this.demoTest = function (browser) {
|
||||
* browser.pause(1000);
|
||||
* // or suspend indefinitely
|
||||
* browser.pause();
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* @method pause
|
||||
* @param {number} ms The number of milliseconds to wait.
|
||||
* @param {function} [callback] Optional callback function to be called when the command finishes.
|
||||
* @api commands
|
||||
*/
|
||||
|
||||
function Pause() {
|
||||
events.EventEmitter.call(this);
|
||||
}
|
||||
|
||||
util.inherits(Pause, events.EventEmitter);
|
||||
|
||||
Pause.prototype.command = function(ms, cb) {
|
||||
var self = this;
|
||||
// If we don't pass the milliseconds, the client will
|
||||
// be suspended indefinitely
|
||||
if (!ms) {
|
||||
return this;
|
||||
}
|
||||
setTimeout(function() {
|
||||
// if we have a callback, call it right before the complete event
|
||||
if (cb) {
|
||||
cb.call(self.client.api);
|
||||
}
|
||||
|
||||
self.emit('complete');
|
||||
}, ms);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
module.exports = Pause;
|
81
tests/node_modules/nightwatch/lib/api/client-commands/perform.js
generated
vendored
Normal file
81
tests/node_modules/nightwatch/lib/api/client-commands/perform.js
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* A simple perform command which allows access to the "api" in a callback.
|
||||
* Can be useful if you want to read variables set by other commands.
|
||||
*
|
||||
* ```
|
||||
* this.demoTest = function (browser) {
|
||||
* var elementValue;
|
||||
* browser
|
||||
* .getValue('.some-element', function(result) {
|
||||
* elementValue = result.value;
|
||||
* })
|
||||
* // other stuff going on ...
|
||||
*
|
||||
* // self-completing callback
|
||||
* .perform(function() {
|
||||
* console.log('elementValue', elementValue);
|
||||
* // without any defined parameters, perform
|
||||
* // completes immediately (synchronously)
|
||||
* })
|
||||
*
|
||||
* // asynchronous completion
|
||||
* .perform(function(done) {
|
||||
* console.log('elementValue', elementValue);
|
||||
* // potentially other async stuff going on
|
||||
* // on finished, call the done callback
|
||||
* done();
|
||||
* })
|
||||
*
|
||||
* // asynchronous completion including api (client)
|
||||
* .perform(function(client, done) {
|
||||
* console.log('elementValue', elementValue);
|
||||
* // similar to before, but now with client
|
||||
* // potentially other async stuff going on
|
||||
* // on finished, call the done callback
|
||||
* done();
|
||||
* });
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* @method perform
|
||||
* @param {function} callback The function to run as part of the queue. Its signature can have up to two parameters. No parameters: callback runs and perform completes immediately at the end of the execution of the callback. One parameter: allows for asynchronous execution within the callback providing a done callback function for completion as the first argument. Two parameters: allows for asynchronous execution with the "api" object passed in as the first argument, followed by the done callback.
|
||||
* @api commands
|
||||
*/
|
||||
|
||||
var util = require('util');
|
||||
var events = require('events');
|
||||
|
||||
function Perform() {
|
||||
events.EventEmitter.call(this);
|
||||
}
|
||||
|
||||
util.inherits(Perform, events.EventEmitter);
|
||||
|
||||
Perform.prototype.command = function(callback) {
|
||||
var self = this;
|
||||
var doneCallback;
|
||||
if (callback.length === 0) {
|
||||
callback.call(self, self.client.api);
|
||||
doneCallback = function() {
|
||||
self.emit('complete');
|
||||
};
|
||||
} else {
|
||||
doneCallback = function() {
|
||||
var args = [function() {
|
||||
self.emit('complete');
|
||||
}];
|
||||
|
||||
if (callback.length > 1) {
|
||||
args.unshift(self.client.api);
|
||||
}
|
||||
|
||||
callback.apply(self, args);
|
||||
};
|
||||
}
|
||||
|
||||
process.nextTick(doneCallback);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
module.exports = Perform;
|
27
tests/node_modules/nightwatch/lib/api/client-commands/useCss.js
generated
vendored
Normal file
27
tests/node_modules/nightwatch/lib/api/client-commands/useCss.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
var util = require('util');
|
||||
var locateStrategy = require('./_locateStrategy.js');
|
||||
|
||||
/**
|
||||
* Sets the locate strategy for selectors to `css selector`, therefore every following selector needs to be specified as css.
|
||||
*
|
||||
* ```
|
||||
* this.demoTest = function (browser) {
|
||||
* browser
|
||||
* .useCss() // we're back to CSS now
|
||||
* .setValue('input[type=text]', 'nightwatch');
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* @method useCss
|
||||
* @param {function} [callback] Optional callback function to be called when the command finishes.
|
||||
* @api commands
|
||||
*/
|
||||
|
||||
function Command() {
|
||||
this.strategy = 'css selector';
|
||||
locateStrategy.call(this);
|
||||
}
|
||||
|
||||
util.inherits(Command, locateStrategy);
|
||||
|
||||
module.exports = Command;
|
20
tests/node_modules/nightwatch/lib/api/client-commands/useRecursion.js
generated
vendored
Normal file
20
tests/node_modules/nightwatch/lib/api/client-commands/useRecursion.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
var util = require('util');
|
||||
var locateStrategy = require('./_locateStrategy.js');
|
||||
|
||||
/**
|
||||
* Sets the locate strategy for selectors to `recursion`, therefore every following selector needs to be an array of element objects
|
||||
* This is used internally for sections of page objects which require element nesting
|
||||
*
|
||||
* @method useRecursion
|
||||
* @param {function} [callback] Optional callback function to be called when the command finishes.
|
||||
* @api commands
|
||||
*/
|
||||
|
||||
function Command() {
|
||||
this.strategy = 'recursion';
|
||||
locateStrategy.call(this);
|
||||
}
|
||||
|
||||
util.inherits(Command, locateStrategy);
|
||||
|
||||
module.exports = Command;
|
27
tests/node_modules/nightwatch/lib/api/client-commands/useXpath.js
generated
vendored
Normal file
27
tests/node_modules/nightwatch/lib/api/client-commands/useXpath.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
var util = require('util');
|
||||
var locateStrategy = require('./_locateStrategy.js');
|
||||
|
||||
/**
|
||||
* Sets the locate strategy for selectors to xpath, therefore every following selector needs to be specified as xpath.
|
||||
*
|
||||
* ```
|
||||
* this.demoTest = function (browser) {
|
||||
* browser
|
||||
* .useXpath() // every selector now must be xpath
|
||||
* .click("//tr[@data-recordid]/span[text()='Search Text']");
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* @method useXpath
|
||||
* @param {function} [callback] Optional callback function to be called when the command finishes.
|
||||
* @api commands
|
||||
*/
|
||||
|
||||
function Command() {
|
||||
this.strategy = 'xpath';
|
||||
locateStrategy.call(this);
|
||||
}
|
||||
|
||||
util.inherits(Command, locateStrategy);
|
||||
|
||||
module.exports = Command;
|
Reference in New Issue
Block a user