refactor app directory structure and add tests
This commit is contained in:
43
tests/node_modules/nightwatch/lib/api/element-commands/_elementByRecursion.js
generated
vendored
Normal file
43
tests/node_modules/nightwatch/lib/api/element-commands/_elementByRecursion.js
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
var util = require('util');
|
||||
var events = require('events');
|
||||
|
||||
/**
|
||||
* Search for an element on the page, starting with the first element of the array, and where each element in the passed array is nested under the previous one. The located element will be returned as a WebElement JSON object.
|
||||
*
|
||||
* @param {Array} elements An array of ancestor element objects containing selector and locateStrategy properties
|
||||
* @param {function} [callback] Optional callback function to be called when the command finishes.
|
||||
* @api protocol
|
||||
*/
|
||||
|
||||
function ElementByRecursion(client) {
|
||||
events.EventEmitter.call(this);
|
||||
this.protocol = require('../protocol.js')(client);
|
||||
}
|
||||
|
||||
util.inherits(ElementByRecursion, events.EventEmitter);
|
||||
|
||||
ElementByRecursion.prototype.command = function(elements, callback) {
|
||||
var self = this;
|
||||
var allElements = elements.slice();
|
||||
|
||||
var topElement = allElements.shift();
|
||||
var el = this.protocol.element(topElement.locateStrategy, topElement.selector, function checkResult(result) {
|
||||
if (result.status !== 0) {
|
||||
callback(result);
|
||||
self.emit('complete', el, self);
|
||||
} else {
|
||||
var nextElement = allElements.shift();
|
||||
var parentId = result.value.ELEMENT;
|
||||
if (nextElement) {
|
||||
self.protocol.elementIdElement(parentId, nextElement.locateStrategy, nextElement.selector, checkResult);
|
||||
} else {
|
||||
callback(result);
|
||||
self.emit('complete', el, self);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
module.exports = ElementByRecursion;
|
94
tests/node_modules/nightwatch/lib/api/element-commands/_elementsByRecursion.js
generated
vendored
Normal file
94
tests/node_modules/nightwatch/lib/api/element-commands/_elementsByRecursion.js
generated
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
var util = require('util');
|
||||
var events = require('events');
|
||||
var Q = require('q');
|
||||
|
||||
/**
|
||||
* Search for multiple elements on the page, starting with the first element of the array, and where each element in the passed array is nested under the previous one. The located element will be returned as a WebElement JSON objects.
|
||||
*
|
||||
* @param {Array} elements An array of ancestor element objects containing selector and locateStrategy properties
|
||||
* @param {function} [callback] Optional callback function to be called when the command finishes.
|
||||
* @api protocol
|
||||
*/
|
||||
|
||||
function ElementsByRecursion(client) {
|
||||
events.EventEmitter.call(this);
|
||||
this.protocol = require('../protocol.js')(client);
|
||||
}
|
||||
|
||||
util.inherits(ElementsByRecursion, events.EventEmitter);
|
||||
|
||||
ElementsByRecursion.prototype.command = function(elements, callback) {
|
||||
var self = this;
|
||||
|
||||
function deferredElementIdElements(el, using, value) {
|
||||
var deferred = Q.defer();
|
||||
var req = self.protocol.elementIdElements(el, using, value, function(result) {
|
||||
deferred.resolve(result);
|
||||
});
|
||||
req.on('error', function() {
|
||||
deferred.reject();
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function createResult(result, foundElements) {
|
||||
return {
|
||||
status: 0,
|
||||
sessionId: result.sessionId,
|
||||
value: foundElements.map(function(e) {
|
||||
return {
|
||||
ELEMENT: e
|
||||
};
|
||||
}),
|
||||
class: result.class,
|
||||
hCode: result.hCode
|
||||
};
|
||||
}
|
||||
|
||||
function aggregateResults(results) {
|
||||
var result;
|
||||
var foundElements = [];
|
||||
for (var i = 0; i < results.length; i++) {
|
||||
result = results[i];
|
||||
if (result.status === 0 && result.value && result.value.length) {
|
||||
result.value.forEach(function(e) {
|
||||
if (foundElements.indexOf(e.ELEMENT) <= -1) {
|
||||
// In case we have multiple matches on the same element, only add once
|
||||
foundElements.push(e.ELEMENT);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return createResult(result, foundElements);
|
||||
}
|
||||
|
||||
var allElements = elements.slice();
|
||||
var topElement = allElements.shift();
|
||||
|
||||
var el = this.protocol.elements(topElement.locateStrategy, topElement.selector, function checkResult() {
|
||||
var result = aggregateResults(arguments);
|
||||
if (result.value.length === 0) {
|
||||
callback(result);
|
||||
self.emit('complete', el, self);
|
||||
return;
|
||||
}
|
||||
|
||||
var nextElement = allElements.shift();
|
||||
if (nextElement) {
|
||||
var promises = [];
|
||||
result.value.forEach(function(el) {
|
||||
var p = deferredElementIdElements(el.ELEMENT, nextElement.locateStrategy, nextElement.selector, checkResult);
|
||||
promises.push(p);
|
||||
});
|
||||
|
||||
Q.all(promises).spread(checkResult);
|
||||
} else {
|
||||
callback(result);
|
||||
self.emit('complete', el, self);
|
||||
}
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
module.exports = ElementsByRecursion;
|
280
tests/node_modules/nightwatch/lib/api/element-commands/_waitForElement.js
generated
vendored
Normal file
280
tests/node_modules/nightwatch/lib/api/element-commands/_waitForElement.js
generated
vendored
Normal file
@@ -0,0 +1,280 @@
|
||||
var util = require('util');
|
||||
var events = require('events');
|
||||
var Logger = require('../../util/logger.js');
|
||||
var Utils = require('../../util/utils.js');
|
||||
|
||||
/*!
|
||||
* Base class for waitForElement commands. It provides a command
|
||||
* method and element* methods to be overwritten by subclasses
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
function WaitForElement() {
|
||||
events.EventEmitter.call(this);
|
||||
this.startTimer = null;
|
||||
this.cb = null;
|
||||
this.ms = null;
|
||||
this.element = null;
|
||||
this.abortOnFailure = typeof this.client.api.globals.abortOnAssertionFailure == 'undefined' || this.client.api.globals.abortOnAssertionFailure;
|
||||
this.selector = null;
|
||||
this.locateStrategy = this.client.locateStrategy || 'css selector';
|
||||
this.rescheduleInterval = this.client.api.globals.waitForConditionPollInterval || this.client.options.waitForConditionPollInterval || 500; //ms
|
||||
this.throwOnMultipleElementsReturned = this.client.api.globals.throwOnMultipleElementsReturned || this.client.options.throwOnMultipleElementsReturned || false;
|
||||
this.protocol = require('../protocol.js')(this.client);
|
||||
}
|
||||
|
||||
util.inherits(WaitForElement, events.EventEmitter);
|
||||
|
||||
/*!
|
||||
* The public command function which will be called by the test runner. Arguments can be passed in a variety of ways.
|
||||
*
|
||||
* The custom message always is last and the callback is always before the message or last if a message is not passed.
|
||||
*
|
||||
* The second argument is always the time in milliseconds. The third argument can be either of:
|
||||
* - abortOnFailure: this can overwrite the default behaviour of aborting the test if the condition is not met within the specified time
|
||||
* - rescheduleInterval: this can overwrite the default polling interval (currently 500ms)
|
||||
* The above can be supplied also together, in which case the rescheduleInterval is specified before the abortOnFailure.
|
||||
*
|
||||
* Some of the multiple usage possibilities:
|
||||
* ---------------------------------------------------------------------------
|
||||
* - with no arguments; in this case a global default timeout is expected
|
||||
* waitForElement('body');
|
||||
*
|
||||
* - with a global default timeout and a callback
|
||||
* waitForElement('body', function() {});
|
||||
*
|
||||
* - with a global default timeout, a callback and a custom message
|
||||
* waitForElement('body', function() {}, 'test message');
|
||||
*
|
||||
* - with only the timeout
|
||||
* waitForElement('body', 500);
|
||||
*
|
||||
* - with a timeout and a custom message
|
||||
* waitForElement('body', 500, 'test message);
|
||||
*
|
||||
* - with a timeout and a callback
|
||||
* waitForElement('body', 500, function() { .. });
|
||||
*
|
||||
* - with a timeout and a custom abortOnFailure
|
||||
* waitForElement('body', 500, true);
|
||||
*
|
||||
* - with a timeout, a custom abortOnFailure and a custom message
|
||||
* waitForElement('body', 500, true, 'test message');
|
||||
*
|
||||
* - with a timeout, a custom abortOnFailure and a callback
|
||||
* waitForElement('body', 500, true, function() { .. });
|
||||
*
|
||||
* - with a timeout, a custom abortOnFailure, a callback and a custom message
|
||||
* waitForElement('body', 500, true, function() { .. }, 'test message');
|
||||
*
|
||||
* - with a timeout, a custom reschedule interval and a callback
|
||||
* waitForElement('body', 500, 100, function() { .. });
|
||||
*
|
||||
* - with a timeout, a custom rescheduleInterval and a custom abortOnFailure
|
||||
* waitForElement('body', 500, 100, false);
|
||||
*
|
||||
*
|
||||
* @param {string} selector
|
||||
* @param {number|function|string} milliseconds
|
||||
* @param {function|boolean|string|number} callbackOrAbort
|
||||
* @returns {WaitForElement}
|
||||
*/
|
||||
WaitForElement.prototype.command = function commandFn(selector, milliseconds, callbackOrAbort) {
|
||||
this.startTimer = new Date().getTime();
|
||||
this.ms = this.setMilliseconds(milliseconds);
|
||||
this._stackTrace = commandFn.stackTrace;
|
||||
|
||||
if (typeof arguments[1] === 'function') {
|
||||
////////////////////////////////////////////////
|
||||
// The command was called with an implied global timeout:
|
||||
//
|
||||
// waitForElement('body', function() {});
|
||||
// waitForElement('body', function() {}, 'custom message');
|
||||
////////////////////////////////////////////////
|
||||
this.cb = arguments[1];
|
||||
} else if (typeof arguments[2] === 'boolean') {
|
||||
////////////////////////////////////////////////
|
||||
// The command was called with a custom abortOnFailure:
|
||||
//
|
||||
// waitForElement('body', 500, false);
|
||||
////////////////////////////////////////////////
|
||||
this.abortOnFailure = arguments[2];
|
||||
|
||||
// The optional callback is the 4th argument now
|
||||
this.cb = arguments[3] || function() {};
|
||||
} else if (typeof arguments[2] === 'number') {
|
||||
////////////////////////////////////////////////
|
||||
// The command was called with a custom rescheduleInterval:
|
||||
//
|
||||
// waitForElement('body', 500, 100);
|
||||
////////////////////////////////////////////////
|
||||
this.rescheduleInterval = arguments[2];
|
||||
|
||||
if (typeof arguments[3] === 'boolean') {
|
||||
////////////////////////////////////////////////
|
||||
// The command was called with a custom rescheduleInterval and custom abortOnFailure:
|
||||
//
|
||||
// waitForElement('body', 500, 100, false);
|
||||
////////////////////////////////////////////////
|
||||
this.abortOnFailure = arguments[3];
|
||||
|
||||
// The optional callback is the 5th argument now
|
||||
this.cb = arguments[4] || function() {};
|
||||
} else {
|
||||
// The optional callback is the 4th argument now
|
||||
this.cb = arguments[3] || function() {};
|
||||
}
|
||||
} else {
|
||||
// The optional callback is the 3th argument now
|
||||
this.cb = (typeof callbackOrAbort === 'function' && callbackOrAbort) || function() {};
|
||||
}
|
||||
|
||||
// support for a custom message
|
||||
this.message = null;
|
||||
if (arguments.length > 1) {
|
||||
var lastArgument = arguments[arguments.length - 1];
|
||||
if (typeof lastArgument === 'string') {
|
||||
this.message = lastArgument;
|
||||
}
|
||||
}
|
||||
|
||||
this.selector = selector;
|
||||
this.checkElement();
|
||||
return this;
|
||||
};
|
||||
|
||||
/*!
|
||||
* @override
|
||||
*/
|
||||
WaitForElement.prototype.elementFound = function(result, now) {};
|
||||
|
||||
/*!
|
||||
* @override
|
||||
*/
|
||||
WaitForElement.prototype.elementNotFound = function(result, now) {};
|
||||
|
||||
/*!
|
||||
* @override
|
||||
*/
|
||||
WaitForElement.prototype.elementVisible = function(result, now) {};
|
||||
|
||||
/*!
|
||||
* @override
|
||||
*/
|
||||
WaitForElement.prototype.elementNotVisible = function(result, now) {};
|
||||
|
||||
/*!
|
||||
* Reschedule the checkElement
|
||||
*/
|
||||
WaitForElement.prototype.reschedule = function(method) {
|
||||
var self = this;
|
||||
method = method || 'checkElement';
|
||||
|
||||
setTimeout(function() {
|
||||
self[method]();
|
||||
}, this.rescheduleInterval);
|
||||
};
|
||||
|
||||
WaitForElement.prototype.complete = function() {
|
||||
var args = Array.prototype.slice.call(arguments, 0);
|
||||
args.push(this);
|
||||
this.cb.apply(this.client.api, args);
|
||||
this.emit('complete');
|
||||
return this;
|
||||
};
|
||||
|
||||
WaitForElement.prototype.pass = function(result, defaultMsg, timeMs) {
|
||||
this.message = this.formatMessage(defaultMsg, timeMs);
|
||||
this.client.assertion(true, null, null, this.message, this.abortOnFailure);
|
||||
return this.complete(result);
|
||||
};
|
||||
|
||||
WaitForElement.prototype.fail = function(result, actual, expected, defaultMsg) {
|
||||
this.message = this.formatMessage(defaultMsg);
|
||||
this.client.assertion(false, actual, expected, this.message, this.abortOnFailure, this._stackTrace);
|
||||
return this.complete(result);
|
||||
};
|
||||
|
||||
/*!
|
||||
* Will start checking if the element exists and if not re-schedule the check
|
||||
* until the timeout expires or the condition has been met
|
||||
*/
|
||||
WaitForElement.prototype.checkElement = function() {
|
||||
var self = this;
|
||||
this.getProtocolCommand(function(result) {
|
||||
var now = new Date().getTime();
|
||||
|
||||
if (result.value && result.value.length > 0) {
|
||||
if (result.value.length > 1) {
|
||||
var message = 'WaitForElement found ' + result.value.length + ' elements for selector "' + self.selector + '".';
|
||||
if (self.throwOnMultipleElementsReturned) {
|
||||
throw new Error(message);
|
||||
} else if (self.client.options.output) {
|
||||
console.log(Logger.colors.green(' Warn: ' + message + ' Only the first one will be checked.'));
|
||||
}
|
||||
}
|
||||
|
||||
self.element = result.value[0].ELEMENT;
|
||||
return self.elementFound(result, now);
|
||||
}
|
||||
|
||||
return self.elementNotFound(result, now);
|
||||
});
|
||||
};
|
||||
|
||||
WaitForElement.prototype.getProtocolCommand = function(callback) {
|
||||
return this.protocol.elements(this.locateStrategy, this.selector, callback);
|
||||
};
|
||||
|
||||
/*!
|
||||
* Will start checking if the element is visible and if not re-schedule the check
|
||||
* until the timeout expires or the condition has been met
|
||||
*/
|
||||
WaitForElement.prototype.isVisible = function() {
|
||||
var self = this;
|
||||
this.protocol.elementIdDisplayed(this.element, function(result) {
|
||||
var now = new Date().getTime();
|
||||
if (result.status === 0 && result.value === true) {
|
||||
// element was visible
|
||||
return self.elementVisible(result, now);
|
||||
}
|
||||
|
||||
if (result.status === -1 && result.errorStatus === 10) {
|
||||
return self.checkElement();
|
||||
}
|
||||
|
||||
return self.elementNotVisible(result, now);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} defaultMsg
|
||||
* @param {number} [timeMs]
|
||||
* @returns {string}
|
||||
*/
|
||||
WaitForElement.prototype.formatMessage = function (defaultMsg, timeMs) {
|
||||
return Utils.format(this.message || defaultMsg, this.selector, timeMs || this.ms);
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the time in milliseconds to wait for the condition, accepting a given value or a globally defined default
|
||||
*
|
||||
* @param {number} [timeoutMs]
|
||||
* @throws Will throw an error if the global default is undefined or a non-number
|
||||
* @returns {number}
|
||||
*/
|
||||
WaitForElement.prototype.setMilliseconds = function (timeoutMs) {
|
||||
if (timeoutMs && typeof timeoutMs === 'number') {
|
||||
return timeoutMs;
|
||||
}
|
||||
|
||||
var globalTimeout = this.client.api.globals.waitForConditionTimeout;
|
||||
if (typeof globalTimeout !== 'number') {
|
||||
throw new Error('waitForElement expects second parameter to have a global default ' +
|
||||
'(waitForConditionTimeout) to be specified if not passed as the second parameter ');
|
||||
}
|
||||
|
||||
return globalTimeout;
|
||||
};
|
||||
|
||||
module.exports = WaitForElement;
|
53
tests/node_modules/nightwatch/lib/api/element-commands/waitForElementNotPresent.js
generated
vendored
Normal file
53
tests/node_modules/nightwatch/lib/api/element-commands/waitForElementNotPresent.js
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
var util = require('util');
|
||||
var WaitForElement = require('./_waitForElement.js');
|
||||
|
||||
/**
|
||||
* Opposite of `waitForElementPresent`. Waits a given time in milliseconds for an element to be not present (i.e. removed) in the page before performing any other commands or assertions.
|
||||
*
|
||||
* If the element is still present after the specified amount of time, the test fails.
|
||||
*
|
||||
* You can change the polling interval by defining a `waitForConditionPollInterval` property (in milliseconds) in as a global property in your `nightwatch.json` or in your external globals file.
|
||||
*
|
||||
* Similarly, a default timeout can be specified as a global `waitForConditionTimeout` property (in milliseconds).
|
||||
*
|
||||
* ```
|
||||
* this.demoTest = function (browser) {
|
||||
* browser.waitForElementNotPresent('#dialog', 1000);
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* @method waitForElementNotPresent
|
||||
* @param {string} selector The selector (CSS / Xpath) used to locate the element.
|
||||
* @param {number} time The number of milliseconds to wait. The runner performs repeated checks every 500 ms.
|
||||
* @param {boolean} [abortOnFailure] By the default if the element is not found the test will fail. Set this to false if you wish for the test to continue even if the assertion fails. To set this globally you can define a property `abortOnAssertionFailure` in your globals.
|
||||
* @param {function} [callback] Optional callback function to be called when the command finishes.
|
||||
* @param {string} [message] Optional message to be shown in the output; the message supports two placeholders: %s for current selector and %d for the time (e.g. Element %s was not in the page for %d ms).
|
||||
* @see waitForElementPresent
|
||||
* @since v0.4.0
|
||||
* @api commands
|
||||
*/
|
||||
function WaitForElementNotPresent() {
|
||||
WaitForElement.call(this);
|
||||
this.expectedValue = 'not found';
|
||||
}
|
||||
|
||||
util.inherits(WaitForElementNotPresent, WaitForElement);
|
||||
|
||||
WaitForElementNotPresent.prototype.elementFound = function(result, now) {
|
||||
if (now - this.startTimer < this.ms) {
|
||||
// element is still there, schedule another check
|
||||
this.reschedule();
|
||||
return this;
|
||||
}
|
||||
|
||||
var defaultMsg = 'Timed out while waiting for element <%s> to be removed for %d milliseconds.';
|
||||
return this.fail(result, 'found', this.expectedValue, defaultMsg);
|
||||
};
|
||||
|
||||
WaitForElementNotPresent.prototype.elementNotFound = function(result, now) {
|
||||
var defaultMsg = 'Element <%s> was not present after %d milliseconds.';
|
||||
|
||||
return this.pass(result, defaultMsg, now - this.startTimer);
|
||||
};
|
||||
|
||||
module.exports = WaitForElementNotPresent;
|
56
tests/node_modules/nightwatch/lib/api/element-commands/waitForElementNotVisible.js
generated
vendored
Normal file
56
tests/node_modules/nightwatch/lib/api/element-commands/waitForElementNotVisible.js
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
var util = require('util');
|
||||
var WaitForElementPresent = require('./waitForElementPresent.js');
|
||||
|
||||
/**
|
||||
* Opposite of `waitForElementVisible`. Waits a given time in milliseconds for an element to be not visible (i.e. hidden but existing) in the page before performing any other commands or assertions.
|
||||
*
|
||||
* If the element fails to be hidden in the specified amount of time, the test fails.
|
||||
*
|
||||
* You can change the polling interval by defining a `waitForConditionPollInterval` property (in milliseconds) in as a global property in your `nightwatch.json` or in your external globals file.
|
||||
*
|
||||
* Similarly, a default timeout can be specified as a global `waitForConditionTimeout` property (in milliseconds).
|
||||
*
|
||||
* ```
|
||||
* this.demoTest = function (browser) {
|
||||
* browser.waitForElementNotVisible('#dialog', 1000);
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* @method waitForElementNotVisible
|
||||
* @param {string} selector The selector (CSS / Xpath) used to locate the element.
|
||||
* @param {number} time The number of milliseconds to wait. The runner performs repeated checks every 500 ms.
|
||||
* @param {boolean} [abortOnFailure] By the default if the element is not found the test will fail. Set this to false if you wish for the test to continue even if the assertion fails. To set this globally you can define a property `abortOnAssertionFailure` in your globals.
|
||||
* @param {function} [callback] Optional callback function to be called when the command finishes.
|
||||
* @param {string} [message] Optional message to be shown in the output; the message supports two placeholders: %s for current selector and %d for the time (e.g. Element %s was not in the page for %d ms).
|
||||
* @since v0.4.0
|
||||
* @see waitForElementVisible
|
||||
* @api commands
|
||||
*/
|
||||
function WaitForElementNotVisible() {
|
||||
WaitForElementPresent.call(this);
|
||||
this.expectedValue = 'not visible';
|
||||
}
|
||||
|
||||
util.inherits(WaitForElementNotVisible, WaitForElementPresent);
|
||||
|
||||
WaitForElementNotVisible.prototype.elementFound = function() {
|
||||
return this.isVisible();
|
||||
};
|
||||
|
||||
WaitForElementNotVisible.prototype.elementVisible = function(result, now) {
|
||||
if (now - this.startTimer < this.ms) {
|
||||
// element wasn't visible, schedule another check
|
||||
this.reschedule('isVisible');
|
||||
return this;
|
||||
}
|
||||
|
||||
var defaultMsg = 'Timed out while waiting for element <%s> to not be visible for %d milliseconds.';
|
||||
return this.fail(result, 'visible', this.expectedValue, defaultMsg);
|
||||
};
|
||||
|
||||
WaitForElementNotVisible.prototype.elementNotVisible = function(result, now) {
|
||||
var defaultMsg = 'Element <%s> was not visible after %d milliseconds.';
|
||||
return this.pass(result, defaultMsg, now - this.startTimer);
|
||||
};
|
||||
|
||||
module.exports = WaitForElementNotVisible;
|
60
tests/node_modules/nightwatch/lib/api/element-commands/waitForElementPresent.js
generated
vendored
Normal file
60
tests/node_modules/nightwatch/lib/api/element-commands/waitForElementPresent.js
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
var util = require('util');
|
||||
var WaitForElement = require('./_waitForElement.js');
|
||||
|
||||
/**
|
||||
* Waits a given time in milliseconds for an element to be present in the page before performing any other commands or assertions.
|
||||
*
|
||||
* If the element fails to be present in the specified amount of time, the test fails. You can change this by setting `abortOnFailure` to `false`.
|
||||
*
|
||||
* You can change the polling interval by defining a `waitForConditionPollInterval` property (in milliseconds) in as a global property in your `nightwatch.json` or in your external globals file.
|
||||
*
|
||||
* Similarly, a default timeout can be specified as a global `waitForConditionTimeout` property (in milliseconds).
|
||||
*
|
||||
* ```
|
||||
* this.demoTest = function (browser) {
|
||||
* browser.waitForElementPresent('body', 1000);
|
||||
* // continue if failed
|
||||
* browser.waitForElementPresent('body', 1000, false);
|
||||
* // with callback
|
||||
* browser.waitForElementPresent('body', 1000, function() {
|
||||
* // do something while we're here
|
||||
* });
|
||||
* // custom Spanish message
|
||||
* browser.waitForElementPresent('body', 1000, 'elemento %s no era presente en %d ms');
|
||||
* // many combinations possible - the message is always the last argument
|
||||
* browser.waitForElementPresent('body', 1000, false, function() {}, 'elemento %s no era presente en %d ms');
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* @method waitForElementPresent
|
||||
* @param {string} selector The selector (CSS / Xpath) used to locate the element.
|
||||
* @param {number} time The number of milliseconds to wait. The runner performs repeated checks every 500 ms.
|
||||
* @param {boolean} [abortOnFailure] By the default if the element is not found the test will fail. Set this to false if you wish for the test to continue even if the assertion fails. To set this globally you can define a property `abortOnAssertionFailure` in your globals.
|
||||
* @param {function} [callback] Optional callback function to be called when the command finishes.
|
||||
* @param {string} [message] Optional message to be shown in the output; the message supports two placeholders: %s for current selector and %d for the time (e.g. Element %s was not in the page for %d ms).
|
||||
* @api commands
|
||||
*/
|
||||
function WaitForElementPresent() {
|
||||
WaitForElement.call(this);
|
||||
this.expectedValue = 'found';
|
||||
}
|
||||
|
||||
util.inherits(WaitForElementPresent, WaitForElement);
|
||||
|
||||
WaitForElementPresent.prototype.elementFound = function(result, now) {
|
||||
var defaultMsg = 'Element <%s> was present after %d milliseconds.';
|
||||
return this.pass(result, defaultMsg, now - this.startTimer);
|
||||
};
|
||||
|
||||
WaitForElementPresent.prototype.elementNotFound = function(result, now) {
|
||||
if (now - this.startTimer < this.ms) {
|
||||
// element wasn't found, schedule another check
|
||||
this.reschedule();
|
||||
return this;
|
||||
}
|
||||
|
||||
var defaultMsg = 'Timed out while waiting for element <%s> to be present for %d milliseconds.';
|
||||
return this.fail({value:false}, 'not found', this.expectedValue, defaultMsg);
|
||||
};
|
||||
|
||||
module.exports = WaitForElementPresent;
|
64
tests/node_modules/nightwatch/lib/api/element-commands/waitForElementVisible.js
generated
vendored
Normal file
64
tests/node_modules/nightwatch/lib/api/element-commands/waitForElementVisible.js
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
var util = require('util');
|
||||
var WaitForElementPresent = require('./waitForElementPresent.js');
|
||||
|
||||
/**
|
||||
* Waits a given time in milliseconds for an element to be visible in the page before performing any other commands or assertions.
|
||||
*
|
||||
* If the element fails to be present and visible in the specified amount of time, the test fails. You can change this by setting `abortOnFailure` to `false`.
|
||||
*
|
||||
* You can change the polling interval by defining a `waitForConditionPollInterval` property (in milliseconds) in as a global property in your `nightwatch.json` or in your external globals file.
|
||||
*
|
||||
* Similarly, a default timeout can be specified as a global `waitForConditionTimeout` property (in milliseconds).
|
||||
*
|
||||
* ```
|
||||
* this.demoTest = function (browser) {
|
||||
* browser.waitForElementVisible('body', 1000);
|
||||
* // continue if failed
|
||||
* browser.waitForElementVisible('body', 1000, false);
|
||||
* // with callback
|
||||
* browser.waitForElementVisible('body', 1000, function() {
|
||||
* // do something while we're here
|
||||
* });
|
||||
* // custom Spanish message
|
||||
* browser.waitForElementVisible('body', 1000, 'elemento %s no era visible en %d ms');
|
||||
* // many combinations possible - the message is always the last argument
|
||||
* browser.waitForElementVisible('body', 1000, false, function() {}, 'elemento %s no era visible en %d ms');
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* @method waitForElementVisible
|
||||
* @param {string} selector The selector (CSS / Xpath) used to locate the element.
|
||||
* @param {number} time The number of milliseconds to wait. The runner performs repeated checks every 500 ms.
|
||||
* @param {boolean} [abortOnFailure] By the default if the element is not found the test will fail. Set this to false if you wish for the test to continue even if the assertion fails. To set this globally you can define a property `abortOnAssertionFailure` in your globals.
|
||||
* @param {function} [callback] Optional callback function to be called when the command finishes.
|
||||
* @param {string} [message] Optional message to be shown in the output; the message supports two placeholders: %s for current selector and %d for the time (e.g. Element %s was not in the page for %d ms).
|
||||
* @api commands
|
||||
*/
|
||||
function WaitForElementVisible() {
|
||||
WaitForElementPresent.call(this);
|
||||
this.expectedValue = 'visible';
|
||||
}
|
||||
|
||||
util.inherits(WaitForElementVisible, WaitForElementPresent);
|
||||
|
||||
WaitForElementVisible.prototype.elementFound = function(result, now) {
|
||||
return this.isVisible();
|
||||
};
|
||||
|
||||
WaitForElementVisible.prototype.elementVisible = function(result, now) {
|
||||
var defaultMsg = 'Element <%s> was visible after %d milliseconds.';
|
||||
return this.pass(result, defaultMsg, now - this.startTimer);
|
||||
};
|
||||
|
||||
WaitForElementVisible.prototype.elementNotVisible = function(result, now) {
|
||||
if (now - this.startTimer < this.ms) {
|
||||
// element wasn't visible, schedule another check
|
||||
this.reschedule('isVisible');
|
||||
return this;
|
||||
}
|
||||
|
||||
var defaultMsg = 'Timed out while waiting for element <%s> to be visible for %d milliseconds.';
|
||||
return this.fail(result, 'not visible', this.expectedValue, defaultMsg);
|
||||
};
|
||||
|
||||
module.exports = WaitForElementVisible;
|
Reference in New Issue
Block a user