refactor app directory structure and add tests
This commit is contained in:
341
tests/node_modules/nightwatch/lib/api/expect/_baseAssertion.js
generated
vendored
Normal file
341
tests/node_modules/nightwatch/lib/api/expect/_baseAssertion.js
generated
vendored
Normal file
@@ -0,0 +1,341 @@
|
||||
/**
|
||||
* Abstract assertion class that will subclass all defined Chai assertions
|
||||
*
|
||||
* All assertions must implement the following api:
|
||||
*
|
||||
* - @type {function}
|
||||
* executeCommand
|
||||
* - @type {string}
|
||||
* elementFound
|
||||
* - @type {function}
|
||||
* elementNotFound
|
||||
* - @type {function}
|
||||
* retryCommand
|
||||
* - @type {string}
|
||||
* expected
|
||||
* - @type {string}
|
||||
* actual
|
||||
* - @type {string}
|
||||
* message
|
||||
* - @type {boolean}
|
||||
* passed
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
var util = require('util');
|
||||
var events = require('events');
|
||||
var Assertion = require('../../core/assertion.js');
|
||||
var chai = require('chai-nightwatch');
|
||||
var flag = chai.flag;
|
||||
var Utils = require('../../util/utils.js');
|
||||
|
||||
function BaseAssertion() {
|
||||
}
|
||||
|
||||
BaseAssertion.ASSERT_FLAGS = [
|
||||
'be',
|
||||
'that',
|
||||
'have',
|
||||
'which',
|
||||
'equal',
|
||||
'contains',
|
||||
'matches',
|
||||
'before',
|
||||
'after',
|
||||
'waitFor'
|
||||
];
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
BaseAssertion.prototype.executeCommand = function(callback) {};
|
||||
|
||||
BaseAssertion.prototype.setAssertion = function(assertion) {
|
||||
this.assertion = assertion;
|
||||
return this;
|
||||
};
|
||||
|
||||
BaseAssertion.prototype.flag = function(key, value) {
|
||||
if (typeof value == 'undefined') {
|
||||
return flag(this.assertion, key);
|
||||
}
|
||||
|
||||
flag(this.assertion, key, value);
|
||||
return this;
|
||||
};
|
||||
|
||||
BaseAssertion.prototype.setClient = function(client) {
|
||||
this.client = client;
|
||||
return this;
|
||||
};
|
||||
|
||||
BaseAssertion.prototype.setProtocol = function(protocol) {
|
||||
this.protocol = protocol;
|
||||
return this;
|
||||
};
|
||||
|
||||
BaseAssertion.prototype.init = function() {
|
||||
this.promise = this.flag('promise');
|
||||
this.element = this.flag('element');
|
||||
this.selector = this.flag('selector');
|
||||
|
||||
this.setNegate();
|
||||
|
||||
this.waitForMs = this.client.api.globals.waitForConditionTimeout || null;
|
||||
if (this.waitForMs) {
|
||||
this.flag('waitFor', this.waitForMs);
|
||||
}
|
||||
this.retryInterval = this.client.api.globals.waitForConditionPollInterval || 500;
|
||||
this.retries = 0;
|
||||
this.messageParts = [];
|
||||
this.abortOnFailure = typeof this.client.api.globals.abortOnAssertionFailure == 'undefined' || this.client.api.globals.abortOnAssertionFailure;
|
||||
this.passed = false;
|
||||
this.expected = null;
|
||||
this.elementResult = null;
|
||||
this.flags = [];
|
||||
};
|
||||
|
||||
BaseAssertion.prototype.start = function() {
|
||||
this.promise.then(this.onPromiseResolved.bind(this), this.onPromiseRejected.bind(this));
|
||||
};
|
||||
|
||||
BaseAssertion.prototype.onPromiseResolved = function(elementResult) {
|
||||
if (elementResult) {
|
||||
this.elementResult = elementResult;
|
||||
}
|
||||
|
||||
this.executeCommand(function(result) {
|
||||
this.resultValue = result.value;
|
||||
this.resultStatus = result.status;
|
||||
this.resultErrorStatus = result.errorStatus;
|
||||
|
||||
this.processFlags();
|
||||
this.elementFound();
|
||||
|
||||
if (!this.passed && this.shouldRetry()) {
|
||||
this.scheduleRetry();
|
||||
} else {
|
||||
this.done();
|
||||
}
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
BaseAssertion.prototype.onPromiseRejected = function(response) {
|
||||
this.processFlags();
|
||||
|
||||
if (this.shouldRetry() && !this.negate) {
|
||||
this.scheduleRetry();
|
||||
return;
|
||||
}
|
||||
|
||||
this.messageParts.push(' - element was not found');
|
||||
this.actual = 'not present';
|
||||
this.expected = 'present';
|
||||
|
||||
this.elementNotFound();
|
||||
this.done();
|
||||
};
|
||||
|
||||
BaseAssertion.prototype.processFlags = function() {
|
||||
BaseAssertion.ASSERT_FLAGS.forEach(function(entry) {
|
||||
var value = this.flag(entry);
|
||||
if ((typeof value != 'undefined') && (typeof this['@' + entry + 'Flag'] == 'function')) {
|
||||
this.flags.push([entry, value]);
|
||||
this['@' + entry + 'Flag'](value);
|
||||
}
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
BaseAssertion.prototype.hasFlag = function(type) {
|
||||
return this.flags.some(function(flag) {
|
||||
return flag[0] === type;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
BaseAssertion.prototype.elementFound = function() {};
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
BaseAssertion.prototype.elementNotFound = function() {};
|
||||
|
||||
BaseAssertion.prototype.done = function() {
|
||||
this.formatMessage();
|
||||
var stackTrace = this.flag('element')._stackTrace;
|
||||
|
||||
Assertion.assert(
|
||||
this.passed,
|
||||
this.actual,
|
||||
this.expected,
|
||||
this.message,
|
||||
this.abortOnFailure,
|
||||
stackTrace
|
||||
);
|
||||
|
||||
this.element.emitter.emit('complete');
|
||||
};
|
||||
|
||||
BaseAssertion.prototype.getResult = function(value, fn) {
|
||||
var result = fn.call(this);
|
||||
this.setNegate();
|
||||
return this.negate ? !result : result;
|
||||
};
|
||||
|
||||
BaseAssertion.prototype.shouldRetryLocateElement = function() {
|
||||
return (!this.elementResult || this.resultStatus === 10 || this.resultErrorStatus === 10);
|
||||
};
|
||||
|
||||
BaseAssertion.prototype.shouldRetry = function() {
|
||||
if (!this.waitForMs) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.elapsedTime = this.getElapsedTime();
|
||||
return (this.elapsedTime < this.waitForMs);
|
||||
};
|
||||
|
||||
BaseAssertion.prototype.getElapsedTime = function() {
|
||||
var timeNow = new Date().getTime();
|
||||
return timeNow - this.element.startTime;
|
||||
};
|
||||
|
||||
BaseAssertion.prototype.scheduleRetry = function() {
|
||||
this.retries++;
|
||||
setTimeout(this.retryCommand.bind(this), this.retryInterval);
|
||||
};
|
||||
|
||||
BaseAssertion.prototype.formatMessage = function() {
|
||||
this.message = Utils.format(this.message || this.message, this.selector);
|
||||
this.message += this.messageParts.join('');
|
||||
};
|
||||
|
||||
BaseAssertion.prototype['@containsFlag'] = function(value) {
|
||||
var verb = (this.hasFlag('that') || this.hasFlag('which')) ? 'contains' : 'contain';
|
||||
this.conditionFlag(value, function() {
|
||||
return this.resultValue ? this.resultValue.indexOf(value) > -1 : false;
|
||||
}, [
|
||||
'not ' + verb,
|
||||
verb
|
||||
]);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
BaseAssertion.prototype['@equalFlag'] = function(value) {
|
||||
var verb;
|
||||
if (this.hasFlag('have')) {
|
||||
verb = (this.hasFlag('that') || this.hasFlag('which')) ? 'equals' : 'equal to';
|
||||
} else {
|
||||
verb = 'equal';
|
||||
}
|
||||
this.conditionFlag(value, function() {
|
||||
return this.resultValue == value;
|
||||
}, [
|
||||
'not ' + verb,
|
||||
verb
|
||||
]);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
BaseAssertion.prototype['@matchesFlag'] = function(re) {
|
||||
var adverb = this.hasFlag('that') || this.hasFlag('which');
|
||||
var verb = adverb ? 'matches' : 'match';
|
||||
this.conditionFlag(re, function() {
|
||||
return re.test(this.resultValue);
|
||||
}, [
|
||||
(adverb ? 'does ' : '') + 'not match',
|
||||
verb
|
||||
]);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
BaseAssertion.prototype.conditionFlag = function(value, conditionFn, arrverb) {
|
||||
this.passed = this.getResult(value, conditionFn);
|
||||
var verb = this.negate ? arrverb[0]: arrverb[1];
|
||||
this.expected = verb + ' \'' + value + '\'';
|
||||
this.actual = this.resultValue;
|
||||
|
||||
if (this.retries > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
var needsSpace = this.messageParts.length === 0 ? true : this.messageParts[this.messageParts.length-1].slice(-1) != ' ';
|
||||
if (needsSpace) {
|
||||
verb = ' ' + verb;
|
||||
}
|
||||
if (!this.customMessage) {
|
||||
this.messageParts.push(
|
||||
verb,
|
||||
': "', value, '"'
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
BaseAssertion.prototype.setNegate = function() {
|
||||
this.negate = this.flag('negate') || false;
|
||||
return this;
|
||||
};
|
||||
|
||||
BaseAssertion.prototype['@beforeFlag'] = function(value) {};
|
||||
|
||||
BaseAssertion.prototype['@afterFlag'] = function(value) {};
|
||||
|
||||
BaseAssertion.prototype['@haveFlag'] = function(value) {};
|
||||
BaseAssertion.prototype['@waitForFlag'] = function(value) {
|
||||
if (this.waitForMs !== value) {
|
||||
this.waitForMs = value;
|
||||
if (!this.customMessage) {
|
||||
this.messageParts.push(this.checkWaitForMsg(this.waitForMs));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
BaseAssertion.prototype['@thatFlag'] = function() {
|
||||
if (this.retries > 0) {
|
||||
return;
|
||||
}
|
||||
if (!this.customMessage) {
|
||||
this.messageParts.push(' that ');
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
BaseAssertion.prototype['@whichFlag'] = function() {
|
||||
if (this.retries > 0) {
|
||||
return;
|
||||
}
|
||||
if (!this.customMessage) {
|
||||
this.messageParts.push(' which ');
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
BaseAssertion.prototype['@beFlag'] = function() {};
|
||||
|
||||
BaseAssertion.prototype.hasCondition = function() {
|
||||
return (this.hasFlag('contains') || this.hasFlag('equal') || this.hasFlag('matches'));
|
||||
};
|
||||
|
||||
BaseAssertion.prototype.checkWaitForMsg = function(waitFor) {
|
||||
var preposition = this.flag('before') && 'in' ||
|
||||
this.flag('after') && 'after' ||
|
||||
'in';
|
||||
return ' ' + preposition +' ' + waitFor + 'ms';
|
||||
};
|
||||
|
||||
BaseAssertion.prototype.retryCommand = function() {
|
||||
if (this.shouldRetryLocateElement()) {
|
||||
this.promise = this.element.createPromise();
|
||||
this.promise.then(this.onPromiseResolved.bind(this), this.onPromiseRejected.bind(this));
|
||||
this.element.locate();
|
||||
} else {
|
||||
this.onPromiseResolved();
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = BaseAssertion;
|
98
tests/node_modules/nightwatch/lib/api/expect/attribute.js
generated
vendored
Normal file
98
tests/node_modules/nightwatch/lib/api/expect/attribute.js
generated
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
/**
|
||||
* Checks if a given attribute of an element exists and optionally if it has the expected value.
|
||||
*
|
||||
* ```
|
||||
* this.demoTest = function (browser) {
|
||||
* browser.expect.element('body').to.have.attribute('data-attr');
|
||||
* browser.expect.element('body').to.not.have.attribute('data-attr');
|
||||
* browser.expect.element('body').to.not.have.attribute('data-attr', 'Testing if body does not have data-attr');
|
||||
* browser.expect.element('body').to.have.attribute('data-attr').before(100);
|
||||
* browser.expect.element('body').to.have.attribute('data-attr')
|
||||
* .equals('some attribute');
|
||||
* browser.expect.element('body').to.have.attribute('data-attr')
|
||||
* .not.equals('other attribute');
|
||||
* browser.expect.element('body').to.have.attribute('data-attr')
|
||||
* .which.contains('something');
|
||||
* browser.expect.element('body').to.have.attribute('data-attr')
|
||||
* .which.matches(/^something\ else/);
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* @method attribute
|
||||
* @param {string} attribute The attribute name
|
||||
* @param {string} [message] Optional log message to display in the output. If missing, one is displayed by default.
|
||||
* @display .attribute(name)
|
||||
* @since v0.7
|
||||
* @api expect
|
||||
*/
|
||||
var util = require('util');
|
||||
var events = require('events');
|
||||
var BaseAssertion = require('./_baseAssertion.js');
|
||||
|
||||
function AttributeAssertion(attribute, msg) {
|
||||
this.flag('attributeFlag', true);
|
||||
this.attribute = attribute;
|
||||
this.customMessage = msg;
|
||||
this.message = msg || 'Expected element <%s> to ' + (this.negate ? 'not have' : 'have') + ' attribute "' + attribute + '"';
|
||||
|
||||
BaseAssertion.call(this);
|
||||
|
||||
this.start();
|
||||
}
|
||||
|
||||
util.inherits(AttributeAssertion, BaseAssertion);
|
||||
|
||||
AttributeAssertion.prototype.executeCommand = function(callback) {
|
||||
this.protocol.elementIdAttribute(this.elementResult.ELEMENT, this.attribute, function(result) {
|
||||
if (result.value !== null && result.status === 0) {
|
||||
callback(result);
|
||||
} else {
|
||||
this.attributeNotFound();
|
||||
}
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
AttributeAssertion.prototype.elementFound = function() {
|
||||
if (this.retries > 0 && this.negate) {
|
||||
return;
|
||||
}
|
||||
if (!this.hasCondition()) {
|
||||
this.passed = this.negate ? false : true;
|
||||
this.expected = this.negate ? 'not found' : 'found';
|
||||
this.actual = 'found';
|
||||
}
|
||||
|
||||
if (this.waitForMs && this.passed) {
|
||||
var message = 'attribute was present';
|
||||
if (this.hasCondition()) {
|
||||
message = 'condition was met';
|
||||
}
|
||||
this.elapsedTime = this.getElapsedTime();
|
||||
this.messageParts.push(' - ' + message + ' in ' + this.elapsedTime + 'ms');
|
||||
}
|
||||
};
|
||||
|
||||
AttributeAssertion.prototype.attributeNotFound = function() {
|
||||
this.processFlags();
|
||||
this.passed = this.hasCondition() ? false : this.negate;
|
||||
|
||||
if (!this.passed && this.shouldRetry()) {
|
||||
this.scheduleRetry();
|
||||
} else {
|
||||
if (!this.hasCondition()) {
|
||||
this.expected = this.negate ? 'not found' : 'found';
|
||||
this.actual = 'not found';
|
||||
}
|
||||
|
||||
if (!this.negate) {
|
||||
this.messageParts.push(' - attribute was not found');
|
||||
}
|
||||
this.done();
|
||||
}
|
||||
};
|
||||
|
||||
AttributeAssertion.prototype.elementNotFound = function() {
|
||||
this.passed = false;
|
||||
};
|
||||
|
||||
module.exports = AttributeAssertion;
|
69
tests/node_modules/nightwatch/lib/api/expect/css.js
generated
vendored
Normal file
69
tests/node_modules/nightwatch/lib/api/expect/css.js
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Checks a given css property of an element exists and optionally if it has the expected value.
|
||||
*
|
||||
* ```
|
||||
* this.demoTest = function (browser) {
|
||||
* browser.expect.element('#main').to.have.css('display');
|
||||
* browser.expect.element('#main').to.have.css('display', 'Testing for display');
|
||||
* browser.expect.element('#main').to.not.have.css('display');
|
||||
* browser.expect.element('#main').to.have.css('display').before(100);
|
||||
* browser.expect.element('#main').to.have.css('display').which.equals('block');
|
||||
* browser.expect.element('#main').to.have.css('display').which.contains('some value');
|
||||
* browser.expect.element('#main').to.have.css('display').which.matches(/some\ value/);
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* @method css
|
||||
* @param {string} property The css property name
|
||||
* @param {string} [message] Optional log message to display in the output. If missing, one is displayed by default.*
|
||||
* @display .css(property)
|
||||
* @since v0.7
|
||||
* @api expect
|
||||
*/
|
||||
var util = require('util');
|
||||
var events = require('events');
|
||||
var BaseAssertion = require('./_baseAssertion.js');
|
||||
|
||||
function CssAssertion(property, msg) {
|
||||
this.cssProperty = property;
|
||||
this.flag('cssFlag', true);
|
||||
|
||||
BaseAssertion.call(this);
|
||||
this.customMessage = typeof msg != 'undefined';
|
||||
this.message = msg || 'Expected element <%s> to ' + (this.negate ? 'not have' : 'have') + ' css property "' + property + '"';
|
||||
this.start();
|
||||
}
|
||||
|
||||
util.inherits(CssAssertion, BaseAssertion);
|
||||
|
||||
CssAssertion.prototype.executeCommand = function(callback) {
|
||||
this.protocol.elementIdCssProperty(this.elementResult.ELEMENT, this.cssProperty, callback);
|
||||
};
|
||||
|
||||
CssAssertion.prototype['@haveFlag'] = function() {
|
||||
this.passed = this.negate ? (this.resultValue === '') : (this.resultValue !== '');
|
||||
this.expected = this.negate ? 'not present' : 'present';
|
||||
this.actual = this.resultValue === '' ? 'not present' : 'present';
|
||||
};
|
||||
|
||||
CssAssertion.prototype.elementFound = function() {
|
||||
if (this.retries > 0 && this.negate) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.passed && this.waitForMs) {
|
||||
var message = 'property was present';
|
||||
|
||||
if (this.hasCondition()) {
|
||||
message = 'condition was met';
|
||||
}
|
||||
this.elapsedTime = this.getElapsedTime();
|
||||
this.messageParts.push(' - ' + message + ' in ' + this.elapsedTime + 'ms');
|
||||
}
|
||||
};
|
||||
|
||||
CssAssertion.prototype.elementNotFound = function() {
|
||||
this.passed = false;
|
||||
};
|
||||
|
||||
module.exports = CssAssertion;
|
55
tests/node_modules/nightwatch/lib/api/expect/enabled.js
generated
vendored
Normal file
55
tests/node_modules/nightwatch/lib/api/expect/enabled.js
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Property that checks if an element is currently enabled.
|
||||
*
|
||||
* ```
|
||||
* this.demoTest = function (browser) {
|
||||
* browser.expect.element('#weblogin').to.be.enabled;
|
||||
* browser.expect.element('#main').to.not.be.enabled;
|
||||
* browser.expect.element('#main').to.be.enabled.before(100);
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* @method enabled
|
||||
* @display .enabled
|
||||
* @since v0.7
|
||||
* @api expect
|
||||
*/
|
||||
var util = require('util');
|
||||
var events = require('events');
|
||||
var BaseAssertion = require('./_baseAssertion.js');
|
||||
|
||||
function EnabledAssertion() {
|
||||
BaseAssertion.call(this);
|
||||
|
||||
this.message = 'Expected element <%s> to ' + (this.negate ? 'not be enabled' : 'be enabled');
|
||||
this.start();
|
||||
}
|
||||
|
||||
util.inherits(EnabledAssertion, BaseAssertion);
|
||||
|
||||
EnabledAssertion.prototype.executeCommand = function(callback) {
|
||||
this.protocol.elementIdEnabled(this.elementResult.ELEMENT, callback);
|
||||
};
|
||||
|
||||
EnabledAssertion.prototype.elementFound = function() {
|
||||
if (this.retries > 0 && this.negate) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.passed = this.negate ? !this.resultValue : this.resultValue;
|
||||
this.expected = this.negate ? 'not enabled' : 'enabled';
|
||||
this.actual = this.resultValue ? 'enabled' : 'not enabled';
|
||||
|
||||
if (this.passed && this.waitForMs) {
|
||||
this.elapsedTime = this.getElapsedTime();
|
||||
this.messageParts.push(' - condition was met in ' + this.elapsedTime + 'ms');
|
||||
}
|
||||
};
|
||||
|
||||
EnabledAssertion.prototype.elementNotFound = function() {
|
||||
this.passed = false;
|
||||
this.expected = this.negate ? 'not enabled' : 'enabled';
|
||||
this.actual = 'not found';
|
||||
};
|
||||
|
||||
module.exports = EnabledAssertion;
|
71
tests/node_modules/nightwatch/lib/api/expect/present.js
generated
vendored
Normal file
71
tests/node_modules/nightwatch/lib/api/expect/present.js
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* Property that checks if an element is present in the DOM.
|
||||
*
|
||||
* ```
|
||||
* this.demoTest = function (browser) {
|
||||
* browser.expect.element('#main').to.be.present;
|
||||
* browser.expect.element('#main').to.not.be.present;
|
||||
* browser.expect.element('#main').to.be.present.before(100);
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* @method present
|
||||
* @display .present
|
||||
* @since v0.7
|
||||
* @api expect
|
||||
*/
|
||||
var util = require('util');
|
||||
var events = require('events');
|
||||
var BaseAssertion = require('./_baseAssertion.js');
|
||||
|
||||
function PresentAssertion() {
|
||||
this.flag('present', true);
|
||||
|
||||
BaseAssertion.call(this);
|
||||
|
||||
this.message = 'Expected element <%s> to ' + (this.negate ? 'not be present' : 'be present');
|
||||
this.start();
|
||||
}
|
||||
|
||||
util.inherits(PresentAssertion, BaseAssertion);
|
||||
|
||||
PresentAssertion.prototype.executeCommand = function(callback) {
|
||||
return callback(this.elementResult);
|
||||
};
|
||||
|
||||
PresentAssertion.prototype.elementFound = function() {
|
||||
this.passed = !this.negate;
|
||||
|
||||
if (!this.passed && this.shouldRetry()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.waitForMs) {
|
||||
this.elapsedTime = this.getElapsedTime();
|
||||
this.messageParts.push(' - element was present in ' + this.elapsedTime + 'ms');
|
||||
}
|
||||
if (this.negate) {
|
||||
this.actual = 'present';
|
||||
this.expected = 'not present';
|
||||
}
|
||||
};
|
||||
|
||||
PresentAssertion.prototype.elementNotFound = function() {
|
||||
this.passed = this.negate;
|
||||
|
||||
if (!this.passed && this.shouldRetry()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.waitForMs && this.negate) {
|
||||
this.messageParts.push(this.checkWaitForMsg(this.elapsedTime) + '.');
|
||||
}
|
||||
};
|
||||
|
||||
PresentAssertion.prototype.retryCommand = function() {
|
||||
this.promise = this.element.createPromise();
|
||||
this.element.deferred.promise.then(this.onPromiseResolved.bind(this), this.onPromiseRejected.bind(this));
|
||||
this.element.locate();
|
||||
};
|
||||
|
||||
module.exports = PresentAssertion;
|
55
tests/node_modules/nightwatch/lib/api/expect/selected.js
generated
vendored
Normal file
55
tests/node_modules/nightwatch/lib/api/expect/selected.js
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Property that checks if an OPTION element, or an INPUT element of type checkbox or radio button is currently selected.
|
||||
*
|
||||
* ```
|
||||
* this.demoTest = function (browser) {
|
||||
* browser.expect.element('#main').to.be.selected;
|
||||
* browser.expect.element('#main').to.not.be.selected;
|
||||
* browser.expect.element('#main').to.be.selected.before(100);
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* @method selected
|
||||
* @display .selected
|
||||
* @since v0.7
|
||||
* @api expect
|
||||
*/
|
||||
var util = require('util');
|
||||
var events = require('events');
|
||||
var BaseAssertion = require('./_baseAssertion.js');
|
||||
|
||||
function SelectedAssertion() {
|
||||
BaseAssertion.call(this);
|
||||
|
||||
this.message = 'Expected element <%s> to ' + (this.negate ? 'not be selected' : 'be selected');
|
||||
this.start();
|
||||
}
|
||||
|
||||
util.inherits(SelectedAssertion, BaseAssertion);
|
||||
|
||||
SelectedAssertion.prototype.executeCommand = function(callback) {
|
||||
this.protocol.elementIdSelected(this.elementResult.ELEMENT, callback);
|
||||
};
|
||||
|
||||
SelectedAssertion.prototype.elementFound = function() {
|
||||
if (this.retries > 0 && this.negate) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.passed = this.negate ? !this.resultValue : this.resultValue;
|
||||
this.expected = this.negate ? 'not selected' : 'selected';
|
||||
this.actual = this.resultValue ? 'selected' : 'not selected';
|
||||
|
||||
if (this.passed && this.waitForMs) {
|
||||
this.elapsedTime = this.getElapsedTime();
|
||||
this.messageParts.push(' - condition was met in ' + this.elapsedTime + 'ms');
|
||||
}
|
||||
};
|
||||
|
||||
SelectedAssertion.prototype.elementNotFound = function() {
|
||||
this.passed = false;
|
||||
this.expected = this.negate ? 'not selected' : 'selected';
|
||||
this.actual = 'not found';
|
||||
};
|
||||
|
||||
module.exports = SelectedAssertion;
|
58
tests/node_modules/nightwatch/lib/api/expect/text.js
generated
vendored
Normal file
58
tests/node_modules/nightwatch/lib/api/expect/text.js
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* Property that retrieves the text contained by an element. Can be chained to check if contains/equals/matches the specified text or regex.
|
||||
*
|
||||
* ```
|
||||
* this.demoTest = function (browser) {
|
||||
* browser.expect.element('#main').text.to.equal('The Night Watch');
|
||||
* browser.expect.element('#main').text.to.not.equal('The Night Watch');
|
||||
* browser.expect.element('#main').text.to.equal('The Night Watch').before(100);
|
||||
* browser.expect.element('#main').text.to.contain('The Night Watch');
|
||||
* browser.expect.element('#main').text.to.match(/The\ Night\ Watch/);
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* @method text
|
||||
* @since v0.7
|
||||
* @display .text
|
||||
* @api expect
|
||||
*/
|
||||
var util = require('util');
|
||||
var events = require('events');
|
||||
var BaseAssertion = require('./_baseAssertion.js');
|
||||
|
||||
function TextAssertion() {
|
||||
this.flag('textFlag', true);
|
||||
|
||||
BaseAssertion.call(this);
|
||||
|
||||
this.message = 'Expected element <%s> text to' + (this.negate ? ' not' : '');
|
||||
this.start();
|
||||
}
|
||||
|
||||
util.inherits(TextAssertion, BaseAssertion);
|
||||
|
||||
TextAssertion.prototype.executeCommand = function(callback) {
|
||||
this.protocol.elementIdText(this.elementResult.ELEMENT, callback);
|
||||
};
|
||||
|
||||
|
||||
TextAssertion.prototype.elementFound = function() {
|
||||
if (this.retries > 0 && this.negate) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.passed && this.waitForMs) {
|
||||
var message = '';
|
||||
if (this.hasCondition()) {
|
||||
message = 'condition was met';
|
||||
}
|
||||
this.elapsedTime = this.getElapsedTime();
|
||||
this.messageParts.push(' - ' + message + ' in ' + this.elapsedTime + 'ms');
|
||||
}
|
||||
};
|
||||
|
||||
TextAssertion.prototype.elementNotFound = function() {
|
||||
this.passed = false;
|
||||
};
|
||||
|
||||
module.exports = TextAssertion;
|
60
tests/node_modules/nightwatch/lib/api/expect/type.js
generated
vendored
Normal file
60
tests/node_modules/nightwatch/lib/api/expect/type.js
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Checks if the type (i.e. tag name) of a specified element is of an expected value.
|
||||
*
|
||||
* ```
|
||||
* this.demoTest = function (browser) {
|
||||
* browser.expect.element('#q').to.be.an('input');
|
||||
* browser.expect.element('#q').to.be.an('input', 'Testing if #q is an input');
|
||||
* browser.expect.element('#w').to.be.a('span');
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* @method a
|
||||
* @display .a(type)
|
||||
* @alias an
|
||||
* @since v0.7
|
||||
* @param {string} type The expected type
|
||||
* @param {string} [message] Optional log message to display in the output. If missing, one is displayed by default.
|
||||
* @api expect
|
||||
*/
|
||||
var util = require('util');
|
||||
var events = require('events');
|
||||
var BaseAssertion = require('./_baseAssertion.js');
|
||||
|
||||
function TypeAssertion(type, msg) {
|
||||
this.type = type;
|
||||
|
||||
BaseAssertion.call(this);
|
||||
|
||||
this.article = ['a', 'e', 'i', 'o'].indexOf(type.substring(0, 1)) > -1 ? 'an' : 'a';
|
||||
this.customMessage = msg;
|
||||
this.message = msg || 'Expected element <%s> to ' + (this.negate ? 'not be' : 'be') + ' ' + this.article +' ' + type;
|
||||
this.start();
|
||||
}
|
||||
|
||||
util.inherits(TypeAssertion, BaseAssertion);
|
||||
|
||||
TypeAssertion.prototype.executeCommand = function(callback) {
|
||||
this.protocol.elementIdName(this.elementResult.ELEMENT, callback);
|
||||
};
|
||||
|
||||
TypeAssertion.prototype.elementFound = function() {
|
||||
if (this.retries > 0 && this.negate) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.passed = this.negate ? (this.resultValue != this.type) : (this.resultValue == this.type);
|
||||
this.expected = this.negate ? 'not be ' + this.article + ' ' + this.type : 'be ' + this.article + ' ' + this.type;
|
||||
this.actual = this.resultValue;
|
||||
|
||||
if (this.passed && this.waitForMs) {
|
||||
this.elapsedTime = this.getElapsedTime();
|
||||
this.messageParts.push(' - condition was met in ' + this.elapsedTime + 'ms');
|
||||
}
|
||||
};
|
||||
|
||||
TypeAssertion.prototype.elementNotFound = function() {
|
||||
this.passed = false;
|
||||
};
|
||||
|
||||
module.exports = TypeAssertion;
|
55
tests/node_modules/nightwatch/lib/api/expect/value.js
generated
vendored
Normal file
55
tests/node_modules/nightwatch/lib/api/expect/value.js
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Property that retrieves the value (i.e. the value attributed) of an element. Can be chained to check if contains/equals/matches the specified text or regex.
|
||||
*
|
||||
* ```
|
||||
* this.demoTest = function (browser) {
|
||||
* browser.expect.element('#q').to.have.value.that.equals('search');
|
||||
* browser.expect.element('#q').to.have.value.not.equals('search');
|
||||
* browser.expect.element('#q').to.have.value.which.contains('search');
|
||||
* browser.expect.element('#q').to.have.value.which.matches(/search/);
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* @display .value
|
||||
* @method value
|
||||
* @api expect
|
||||
*/
|
||||
var util = require('util');
|
||||
var events = require('events');
|
||||
var BaseAssertion = require('./_baseAssertion.js');
|
||||
|
||||
function ValueAssertion() {
|
||||
this.flag('valueFlag', true);
|
||||
|
||||
BaseAssertion.call(this);
|
||||
|
||||
this.message = 'Expected element <%s> to have value' + (this.negate ? ' not' : '');
|
||||
this.start();
|
||||
}
|
||||
|
||||
util.inherits(ValueAssertion, BaseAssertion);
|
||||
|
||||
ValueAssertion.prototype.executeCommand = function(callback) {
|
||||
this.protocol.elementIdValue(this.elementResult.ELEMENT, callback);
|
||||
};
|
||||
|
||||
ValueAssertion.prototype.elementFound = function() {
|
||||
if (this.retries > 0 && this.negate) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.passed && this.waitForMs) {
|
||||
var message = '';
|
||||
if (this.hasCondition()) {
|
||||
message = 'condition was met';
|
||||
}
|
||||
this.elapsedTime = this.getElapsedTime();
|
||||
this.messageParts.push(' - ' + message + ' in ' + this.elapsedTime + 'ms');
|
||||
}
|
||||
};
|
||||
|
||||
ValueAssertion.prototype.elementNotFound = function() {
|
||||
this.passed = false;
|
||||
};
|
||||
|
||||
module.exports = ValueAssertion;
|
49
tests/node_modules/nightwatch/lib/api/expect/visible.js
generated
vendored
Normal file
49
tests/node_modules/nightwatch/lib/api/expect/visible.js
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Property that asserts the visibility of a specified element.
|
||||
*
|
||||
* ```
|
||||
* this.demoTest = function (browser) {
|
||||
* browser.expect.element('#main').to.be.visible;
|
||||
* browser.expect.element('#main').to.not.be.visible;
|
||||
* browser.expect.element('#main').to.be.visible.before(100);
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* @display .visible
|
||||
* @method visible
|
||||
* @api expect
|
||||
*/
|
||||
var util = require('util');
|
||||
var BaseAssertion = require('./_baseAssertion.js');
|
||||
|
||||
function VisibleAssertion() {
|
||||
BaseAssertion.call(this);
|
||||
|
||||
this.message = 'Expected element <%s> to ' + (this.negate ? 'not be visible' : 'be visible');
|
||||
this.start();
|
||||
}
|
||||
|
||||
util.inherits(VisibleAssertion, BaseAssertion);
|
||||
|
||||
VisibleAssertion.prototype.executeCommand = function(callback) {
|
||||
this.protocol.elementIdDisplayed(this.elementResult.ELEMENT, callback);
|
||||
};
|
||||
|
||||
VisibleAssertion.prototype.elementFound = function() {
|
||||
this.passed = this.negate ? this.resultValue === false : this.resultValue;
|
||||
this.expected = this.negate ? 'not visible' : 'visible';
|
||||
this.actual = this.resultValue ? 'visible' : 'not visible';
|
||||
|
||||
if (this.passed && this.waitForMs) {
|
||||
this.elapsedTime = this.getElapsedTime();
|
||||
this.messageParts.push(' - condition was met in ' + this.elapsedTime + 'ms');
|
||||
}
|
||||
};
|
||||
|
||||
VisibleAssertion.prototype.elementNotFound = function() {
|
||||
this.passed = false;
|
||||
this.expected = this.negate ? 'not visible' : 'visible';
|
||||
this.actual = 'not found';
|
||||
};
|
||||
|
||||
module.exports = VisibleAssertion;
|
Reference in New Issue
Block a user