refactor app directory structure and add tests
This commit is contained in:
57
tests/node_modules/nightwatch/lib/api/assertions/attributeContains.js
generated
vendored
Normal file
57
tests/node_modules/nightwatch/lib/api/assertions/attributeContains.js
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* Checks if the given attribute of an element contains the expected value.
|
||||
*
|
||||
* ```
|
||||
* this.demoTest = function (client) {
|
||||
* browser.assert.attributeContains('#someElement', 'href', 'google.com');
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* @method attributeContains
|
||||
* @param {string} selector The selector (CSS / Xpath) used to locate the element.
|
||||
* @param {string} attribute The attribute name
|
||||
* @param {string} expected The expected contained value of the attribute to check.
|
||||
* @param {string} [message] Optional log message to display in the output. If missing, one is displayed by default.
|
||||
* @api assertions
|
||||
*/
|
||||
|
||||
var util = require('util');
|
||||
exports.assertion = function(selector, attribute, expected, msg) {
|
||||
var DEFAULT_MSG = 'Testing if attribute %s of <%s> contains "%s".';
|
||||
var MSG_ELEMENT_NOT_FOUND = DEFAULT_MSG + ' ' + 'Element could not be located.';
|
||||
var MSG_ATTR_NOT_FOUND = DEFAULT_MSG + ' ' + 'Element does not have a ' + attribute + ' attribute.';
|
||||
|
||||
this.message = msg || util.format(DEFAULT_MSG, attribute, selector, expected);
|
||||
|
||||
this.expected = function() {
|
||||
return expected;
|
||||
};
|
||||
|
||||
this.pass = function(value) {
|
||||
return value.indexOf(expected) > -1;
|
||||
};
|
||||
|
||||
this.failure = function(result) {
|
||||
var failed = (result === false) ||
|
||||
// no such element
|
||||
result && (result.status === -1 || result.value === null);
|
||||
|
||||
if (failed) {
|
||||
var defaultMsg = MSG_ELEMENT_NOT_FOUND;
|
||||
if (result && result.value === null) {
|
||||
defaultMsg = MSG_ATTR_NOT_FOUND;
|
||||
}
|
||||
this.message = msg || util.format(defaultMsg, attribute, selector, expected);
|
||||
}
|
||||
return failed;
|
||||
};
|
||||
|
||||
this.value = function(result) {
|
||||
return result.value;
|
||||
};
|
||||
|
||||
this.command = function(callback) {
|
||||
return this.api.getAttribute(selector, attribute, callback);
|
||||
};
|
||||
|
||||
};
|
57
tests/node_modules/nightwatch/lib/api/assertions/attributeEquals.js
generated
vendored
Normal file
57
tests/node_modules/nightwatch/lib/api/assertions/attributeEquals.js
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* Checks if the given attribute of an element has the expected value.
|
||||
*
|
||||
* ```
|
||||
* this.demoTest = function (client) {
|
||||
* browser.assert.attributeEquals('body', 'data-attr', 'some value');
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* @method attributeEquals
|
||||
* @param {string} selector The selector (CSS / Xpath) used to locate the element.
|
||||
* @param {string} attribute The attribute name
|
||||
* @param {string} expected The expected value of the attribute to check.
|
||||
* @param {string} [message] Optional log message to display in the output. If missing, one is displayed by default.
|
||||
* @api assertions
|
||||
*/
|
||||
|
||||
var util = require('util');
|
||||
exports.assertion = function(selector, attribute, expected, msg) {
|
||||
var DEFAULT_MSG = 'Testing if attribute %s of <%s> equals "%s".';
|
||||
var MSG_ELEMENT_NOT_FOUND = DEFAULT_MSG + ' ' + 'Element could not be located.';
|
||||
var MSG_ATTR_NOT_FOUND = DEFAULT_MSG + ' ' + 'Element does not have a ' + attribute + ' attribute.';
|
||||
|
||||
this.message = msg || util.format(DEFAULT_MSG, attribute, selector, expected);
|
||||
|
||||
this.expected = function() {
|
||||
return expected;
|
||||
};
|
||||
|
||||
this.pass = function(value) {
|
||||
return value === expected;
|
||||
};
|
||||
|
||||
this.failure = function(result) {
|
||||
var failed = (result === false) ||
|
||||
// no such element
|
||||
result && (result.status === -1 || result.value === null);
|
||||
|
||||
if (failed) {
|
||||
var defaultMsg = MSG_ELEMENT_NOT_FOUND;
|
||||
if (result && result.value === null) {
|
||||
defaultMsg = MSG_ATTR_NOT_FOUND;
|
||||
}
|
||||
this.message = msg || util.format(defaultMsg, attribute, selector, expected);
|
||||
}
|
||||
return failed;
|
||||
};
|
||||
|
||||
this.value = function(result) {
|
||||
return result.value;
|
||||
};
|
||||
|
||||
this.command = function(callback) {
|
||||
return this.api.getAttribute(selector, attribute, callback);
|
||||
};
|
||||
|
||||
};
|
49
tests/node_modules/nightwatch/lib/api/assertions/containsText.js
generated
vendored
Normal file
49
tests/node_modules/nightwatch/lib/api/assertions/containsText.js
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Checks if the given element contains the specified text.
|
||||
*
|
||||
* ```
|
||||
* this.demoTest = function (client) {
|
||||
* browser.assert.containsText('#main', 'The Night Watch');
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* @method containsText
|
||||
* @param {string} selector The selector (CSS / Xpath) used to locate the element.
|
||||
* @param {string} expectedText The text to look for.
|
||||
* @param {string} [message] Optional log message to display in the output. If missing, one is displayed by default.
|
||||
* @api assertions
|
||||
*/
|
||||
|
||||
var util = require('util');
|
||||
exports.assertion = function(selector, expectedText, msg) {
|
||||
|
||||
var MSG_ELEMENT_NOT_FOUND = 'Testing if element <%s> contains text: "%s". ' +
|
||||
'Element could not be located.';
|
||||
|
||||
this.message = msg || util.format('Testing if element <%s> contains text: "%s".', selector, expectedText);
|
||||
|
||||
this.expected = function() {
|
||||
return expectedText;
|
||||
};
|
||||
|
||||
this.pass = function(value) {
|
||||
return value.indexOf(expectedText) > -1;
|
||||
};
|
||||
|
||||
this.failure = function(result) {
|
||||
var failed = result === false || result && result.status === -1;
|
||||
if (failed) {
|
||||
this.message = msg || util.format(MSG_ELEMENT_NOT_FOUND, selector, expectedText);
|
||||
}
|
||||
return failed;
|
||||
};
|
||||
|
||||
this.value = function(result) {
|
||||
return result.value;
|
||||
};
|
||||
|
||||
this.command = function(callback) {
|
||||
return this.api.getText(selector, callback);
|
||||
};
|
||||
|
||||
};
|
50
tests/node_modules/nightwatch/lib/api/assertions/cssClassNotPresent.js
generated
vendored
Normal file
50
tests/node_modules/nightwatch/lib/api/assertions/cssClassNotPresent.js
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Checks if the given element does not have the specified CSS class.
|
||||
*
|
||||
* ```
|
||||
* this.demoTest = function (client) {
|
||||
* browser.assert.cssClassNotPresent('#main', 'container');
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* @method cssClassNotPresent
|
||||
* @param {string} selector The selector (CSS / Xpath) used to locate the element.
|
||||
* @param {string} className The CSS class to look for.
|
||||
* @param {string} [message] Optional log message to display in the output. If missing, one is displayed by default.
|
||||
* @api assertions
|
||||
*/
|
||||
|
||||
var util = require('util');
|
||||
exports.assertion = function(selector, className, msg) {
|
||||
|
||||
var MSG_ELEMENT_NOT_FOUND = 'Testing if element <%s> does not have css class: "%s". ' +
|
||||
'Element could not be located.';
|
||||
|
||||
this.message = msg || util.format('Testing if element <%s> does not have css class: "%s".', selector, className);
|
||||
|
||||
this.expected = function() {
|
||||
return 'without ' + className;
|
||||
};
|
||||
|
||||
this.pass = function(value) {
|
||||
var classes = value.split(' ');
|
||||
return classes.indexOf(className) === -1;
|
||||
};
|
||||
|
||||
this.failure = function(result) {
|
||||
var failed = result === false || result && result.status === -1;
|
||||
if (failed) {
|
||||
this.message = msg || util.format(MSG_ELEMENT_NOT_FOUND, selector, className);
|
||||
}
|
||||
return failed;
|
||||
};
|
||||
|
||||
this.value = function(result) {
|
||||
return result.value;
|
||||
};
|
||||
|
||||
this.command = function(callback) {
|
||||
return this.api.getAttribute(selector, 'class', callback);
|
||||
};
|
||||
|
||||
};
|
50
tests/node_modules/nightwatch/lib/api/assertions/cssClassPresent.js
generated
vendored
Normal file
50
tests/node_modules/nightwatch/lib/api/assertions/cssClassPresent.js
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Checks if the given element has the specified CSS class.
|
||||
*
|
||||
* ```
|
||||
* this.demoTest = function (client) {
|
||||
* browser.assert.cssClassPresent('#main', 'container');
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* @method cssClassPresent
|
||||
* @param {string} selector The selector (CSS / Xpath) used to locate the element.
|
||||
* @param {string} className The CSS class to look for.
|
||||
* @param {string} [message] Optional log message to display in the output. If missing, one is displayed by default.
|
||||
* @api assertions
|
||||
*/
|
||||
|
||||
var util = require('util');
|
||||
exports.assertion = function(selector, className, msg) {
|
||||
|
||||
var MSG_ELEMENT_NOT_FOUND = 'Testing if element <%s> has css class: "%s". ' +
|
||||
'Element could not be located.';
|
||||
|
||||
this.message = msg || util.format('Testing if element <%s> has css class: "%s".', selector, className);
|
||||
|
||||
this.expected = function() {
|
||||
return 'has ' + className;
|
||||
};
|
||||
|
||||
this.pass = function(value) {
|
||||
var classes = value.split(' ');
|
||||
return classes.indexOf(className) > -1;
|
||||
};
|
||||
|
||||
this.failure = function(result) {
|
||||
var failed = result === false || result && result.status === -1;
|
||||
if (failed) {
|
||||
this.message = msg || util.format(MSG_ELEMENT_NOT_FOUND, selector, className);
|
||||
}
|
||||
return failed;
|
||||
};
|
||||
|
||||
this.value = function(result) {
|
||||
return result.value;
|
||||
};
|
||||
|
||||
this.command = function(callback) {
|
||||
return this.api.getAttribute(selector, 'class', callback);
|
||||
};
|
||||
|
||||
};
|
47
tests/node_modules/nightwatch/lib/api/assertions/cssProperty.js
generated
vendored
Normal file
47
tests/node_modules/nightwatch/lib/api/assertions/cssProperty.js
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Checks if the specified css property of a given element has the expected value.
|
||||
*
|
||||
* ```
|
||||
* this.demoTest = function (client) {
|
||||
* browser.assert.cssProperty('#main', 'display', 'block');
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* @method cssProperty
|
||||
* @param {string} selector The selector (CSS / Xpath) used to locate the element.
|
||||
* @param {string} cssProperty The CSS property.
|
||||
* @param {string} expected The expected value of the css property to check.
|
||||
* @param {string} [message] Optional log message to display in the output. If missing, one is displayed by default.
|
||||
* @api assertions
|
||||
*/
|
||||
|
||||
var util = require('util');
|
||||
exports.assertion = function(selector, cssProperty, expected, msg) {
|
||||
|
||||
var MSG_ELEMENT_NOT_FOUND = 'Testing if element <%s> has css property %s. ' +
|
||||
'Element or attribute could not be located.';
|
||||
|
||||
this.message = msg || util.format('Testing if element <%s> has css property "%s: %s".', selector, cssProperty, expected);
|
||||
this.expected = expected;
|
||||
|
||||
this.pass = function(value) {
|
||||
return value === expected;
|
||||
};
|
||||
|
||||
this.failure = function(result) {
|
||||
var failed = result === false || result && result.status === -1;
|
||||
if (failed) {
|
||||
this.message = msg || util.format(MSG_ELEMENT_NOT_FOUND, selector, cssProperty);
|
||||
}
|
||||
return failed;
|
||||
};
|
||||
|
||||
this.value = function(result) {
|
||||
return result.value;
|
||||
};
|
||||
|
||||
this.command = function(callback) {
|
||||
return this.api.getCssProperty(selector, cssProperty, callback);
|
||||
};
|
||||
|
||||
};
|
34
tests/node_modules/nightwatch/lib/api/assertions/elementNotPresent.js
generated
vendored
Normal file
34
tests/node_modules/nightwatch/lib/api/assertions/elementNotPresent.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Checks if the given element exists in the DOM.
|
||||
*
|
||||
* ```
|
||||
* this.demoTest = function (client) {
|
||||
* browser.assert.elementNotPresent(".should_not_exist");
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* @method elementNotPresent
|
||||
* @param {string} selector The selector (CSS / Xpath) used to locate the element.
|
||||
* @param {string} [message] Optional log message to display in the output. If missing, one is displayed by default.
|
||||
* @api assertions
|
||||
*/
|
||||
|
||||
var util = require('util');
|
||||
exports.assertion = function(selector, msg) {
|
||||
|
||||
this.message = msg || util.format('Testing if element <%s> is not present.', selector);
|
||||
this.expected = 'not present';
|
||||
|
||||
this.pass = function(value) {
|
||||
return value === 'not present';
|
||||
};
|
||||
|
||||
this.value = function(result) {
|
||||
return (result.status !== 0 || result.value.length === 0) ? 'not present' : 'present';
|
||||
};
|
||||
|
||||
this.command = function(callback) {
|
||||
return this.api.elements(this.client.locateStrategy, selector, callback);
|
||||
};
|
||||
|
||||
};
|
34
tests/node_modules/nightwatch/lib/api/assertions/elementPresent.js
generated
vendored
Normal file
34
tests/node_modules/nightwatch/lib/api/assertions/elementPresent.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Checks if the given element exists in the DOM.
|
||||
*
|
||||
* ```
|
||||
* this.demoTest = function (client) {
|
||||
* browser.assert.elementPresent("#main");
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* @method elementPresent
|
||||
* @param {string} selector The selector (CSS / Xpath) used to locate the element.
|
||||
* @param {string} [message] Optional log message to display in the output. If missing, one is displayed by default.
|
||||
* @api assertions
|
||||
*/
|
||||
|
||||
var util = require('util');
|
||||
exports.assertion = function(selector, msg) {
|
||||
|
||||
this.message = msg || util.format('Testing if element <%s> is present.', selector);
|
||||
this.expected = 'present';
|
||||
|
||||
this.pass = function(value) {
|
||||
return value == 'present';
|
||||
};
|
||||
|
||||
this.value = function(result) {
|
||||
return (result.status !== 0 || result.value.length === 0) ? 'not present' : 'present';
|
||||
};
|
||||
|
||||
this.command = function(callback) {
|
||||
return this.api.elements(this.client.locateStrategy, selector, callback);
|
||||
};
|
||||
|
||||
};
|
45
tests/node_modules/nightwatch/lib/api/assertions/hidden.js
generated
vendored
Normal file
45
tests/node_modules/nightwatch/lib/api/assertions/hidden.js
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Checks if the given element is not visible on the page.
|
||||
*
|
||||
* ```
|
||||
* this.demoTest = function (client) {
|
||||
* browser.assert.hidden(".should_not_be_visible");
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* @method hidden
|
||||
* @param {string} selector The selector (CSS / Xpath) used to locate the element.
|
||||
* @param {string} [message] Optional log message to display in the output. If missing, one is displayed by default.
|
||||
* @api assertions
|
||||
*/
|
||||
|
||||
var util = require('util');
|
||||
exports.assertion = function(selector, msg) {
|
||||
|
||||
var MSG_ELEMENT_NOT_FOUND = 'Testing if element <%s> is hidden. ' +
|
||||
'Element could not be located.';
|
||||
|
||||
this.message = msg || util.format('Testing if element <%s> is hidden.', selector);
|
||||
this.expected = true;
|
||||
|
||||
this.pass = function(value) {
|
||||
return value === this.expected;
|
||||
};
|
||||
|
||||
this.failure = function(result) {
|
||||
var failed = result === false || result && result.status === -1;
|
||||
if (failed) {
|
||||
this.message = msg || util.format(MSG_ELEMENT_NOT_FOUND, selector);
|
||||
}
|
||||
return failed;
|
||||
};
|
||||
|
||||
this.value = function(result) {
|
||||
return !result.value;
|
||||
};
|
||||
|
||||
this.command = function(callback) {
|
||||
return this.api.isVisible(selector, callback);
|
||||
};
|
||||
|
||||
};
|
35
tests/node_modules/nightwatch/lib/api/assertions/title.js
generated
vendored
Normal file
35
tests/node_modules/nightwatch/lib/api/assertions/title.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Checks if the page title equals the given value.
|
||||
*
|
||||
* ```
|
||||
* this.demoTest = function (client) {
|
||||
* browser.assert.title("Nightwatch.js");
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* @method title
|
||||
* @param {string} expected The expected page title.
|
||||
* @param {string} [message] Optional log message to display in the output. If missing, one is displayed by default.
|
||||
* @api assertions
|
||||
*/
|
||||
|
||||
var util = require('util');
|
||||
exports.assertion = function(expected, msg) {
|
||||
|
||||
this.message = msg || util.format('Testing if the page title equals "%s".', expected);
|
||||
this.expected = expected;
|
||||
|
||||
this.pass = function(value) {
|
||||
return value === this.expected;
|
||||
};
|
||||
|
||||
this.value = function(result) {
|
||||
return result.value;
|
||||
};
|
||||
|
||||
this.command = function(callback) {
|
||||
this.api.title(callback);
|
||||
return this;
|
||||
};
|
||||
|
||||
};
|
35
tests/node_modules/nightwatch/lib/api/assertions/urlContains.js
generated
vendored
Normal file
35
tests/node_modules/nightwatch/lib/api/assertions/urlContains.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Checks if the current URL contains the given value.
|
||||
*
|
||||
* ```
|
||||
* this.demoTest = function (client) {
|
||||
* browser.assert.urlContains('google');
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* @method urlContains
|
||||
* @param {string} expected The value expected to exist within the current URL.
|
||||
* @param {string} [message] Optional log message to display in the output. If missing, one is displayed by default.
|
||||
* @api assertions
|
||||
*/
|
||||
|
||||
var util = require('util');
|
||||
exports.assertion = function(expected, msg) {
|
||||
|
||||
this.message = msg || util.format('Testing if the URL contains "%s".', expected);
|
||||
this.expected = expected;
|
||||
|
||||
this.pass = function(value) {
|
||||
return value.indexOf(this.expected) > -1;
|
||||
};
|
||||
|
||||
this.value = function(result) {
|
||||
return result.value;
|
||||
};
|
||||
|
||||
this.command = function(callback) {
|
||||
this.api.url(callback);
|
||||
return this;
|
||||
};
|
||||
|
||||
};
|
35
tests/node_modules/nightwatch/lib/api/assertions/urlEquals.js
generated
vendored
Normal file
35
tests/node_modules/nightwatch/lib/api/assertions/urlEquals.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Checks if the current url equals the given value.
|
||||
*
|
||||
* ```
|
||||
* this.demoTest = function (client) {
|
||||
* browser.assert.urlEquals('http://www.google.com');
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* @method urlEquals
|
||||
* @param {string} expected The expected url.
|
||||
* @param {string} [message] Optional log message to display in the output. If missing, one is displayed by default.
|
||||
* @api assertions
|
||||
*/
|
||||
|
||||
var util = require('util');
|
||||
exports.assertion = function(expected, msg) {
|
||||
|
||||
this.message = msg || util.format('Testing if the URL equals "%s".', expected);
|
||||
this.expected = expected;
|
||||
|
||||
this.pass = function(value) {
|
||||
return value === this.expected;
|
||||
};
|
||||
|
||||
this.value = function(result) {
|
||||
return result.value;
|
||||
};
|
||||
|
||||
this.command = function(callback) {
|
||||
this.api.url(callback);
|
||||
return this;
|
||||
};
|
||||
|
||||
};
|
50
tests/node_modules/nightwatch/lib/api/assertions/value.js
generated
vendored
Normal file
50
tests/node_modules/nightwatch/lib/api/assertions/value.js
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Checks if the given form element's value equals the expected value.
|
||||
*
|
||||
* ```
|
||||
* this.demoTest = function (client) {
|
||||
* browser.assert.value("form.login input[type=text]", "username");
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* @method value
|
||||
* @param {string} selector The selector (CSS / Xpath) used to locate the element.
|
||||
* @param {string} expectedText The expected text.
|
||||
* @param {string} [message] Optional log message to display in the output. If missing, one is displayed by default.
|
||||
* @api assertions
|
||||
*/
|
||||
|
||||
var util = require('util');
|
||||
exports.assertion = function(selector, expected, msg) {
|
||||
|
||||
var MSG_ELEMENT_NOT_FOUND = 'Testing if value of <%s> equals: "%s". ' +
|
||||
'Element or attribute could not be located.';
|
||||
|
||||
this.message = msg || util.format('Testing if value of <%s> equals: "%s".', selector, expected);
|
||||
this.expected = expected;
|
||||
|
||||
this.pass = function(value) {
|
||||
return value === this.expected;
|
||||
};
|
||||
|
||||
this.failure = function(result) {
|
||||
var failed = (result === false) ||
|
||||
// no such element
|
||||
result && result.status === -1 ||
|
||||
// element doesn't have a value attribute
|
||||
result && result.value === null;
|
||||
if (failed) {
|
||||
this.message = msg || util.format(MSG_ELEMENT_NOT_FOUND, selector, expected);
|
||||
}
|
||||
return failed;
|
||||
};
|
||||
|
||||
this.value = function(result) {
|
||||
return result.value;
|
||||
};
|
||||
|
||||
this.command = function(callback) {
|
||||
return this.api.getValue(selector, callback);
|
||||
};
|
||||
|
||||
};
|
53
tests/node_modules/nightwatch/lib/api/assertions/valueContains.js
generated
vendored
Normal file
53
tests/node_modules/nightwatch/lib/api/assertions/valueContains.js
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Checks if the given form element's value contains the expected value.
|
||||
*
|
||||
* ```
|
||||
* this.demoTest = function (client) {
|
||||
* browser.assert.valueContains("form.login input[type=text]", "username");
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* @method valueContains
|
||||
* @param {string} selector The selector (CSS / Xpath) used to locate the element.
|
||||
* @param {string} expectedText The expected text.
|
||||
* @param {string} [message] Optional log message to display in the output. If missing, one is displayed by default.
|
||||
* @api assertions
|
||||
*/
|
||||
|
||||
var util = require('util');
|
||||
exports.assertion = function(selector, expected, msg) {
|
||||
var DEFAULT_MSG = 'Testing if value of <%s> contains: "%s".';
|
||||
var MSG_ELEMENT_NOT_FOUND = DEFAULT_MSG + ' ' + 'Element could not be located.';
|
||||
var VALUE_ATTR_NOT_FOUND = DEFAULT_MSG + ' ' + 'Element does not have a value attribute.';
|
||||
|
||||
this.message = msg || util.format(DEFAULT_MSG, selector, expected);
|
||||
this.expected = true;
|
||||
|
||||
this.pass = function(value) {
|
||||
return value.indexOf(expected) > -1;
|
||||
};
|
||||
|
||||
this.failure = function(result) {
|
||||
var failed = (result === false) ||
|
||||
// no such element
|
||||
result && (result.status === -1 || result.value === null);
|
||||
|
||||
if (failed) {
|
||||
var defaultMsg = MSG_ELEMENT_NOT_FOUND;
|
||||
if (result && result.value === null) {
|
||||
defaultMsg = VALUE_ATTR_NOT_FOUND;
|
||||
}
|
||||
this.message = msg || util.format(defaultMsg, selector, expected);
|
||||
}
|
||||
return failed;
|
||||
};
|
||||
|
||||
this.value = function(result) {
|
||||
return result.value;
|
||||
};
|
||||
|
||||
this.command = function(callback) {
|
||||
return this.api.getValue(selector, callback);
|
||||
};
|
||||
|
||||
};
|
45
tests/node_modules/nightwatch/lib/api/assertions/visible.js
generated
vendored
Normal file
45
tests/node_modules/nightwatch/lib/api/assertions/visible.js
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Checks if the given element is visible on the page.
|
||||
*
|
||||
* ```
|
||||
* this.demoTest = function (client) {
|
||||
* browser.assert.visible(".should_be_visible");
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* @method visible
|
||||
* @param {string} selector The selector (CSS / Xpath) used to locate the element.
|
||||
* @param {string} [message] Optional log message to display in the output. If missing, one is displayed by default.
|
||||
* @api assertions
|
||||
*/
|
||||
|
||||
var util = require('util');
|
||||
exports.assertion = function(selector, msg) {
|
||||
|
||||
var MSG_ELEMENT_NOT_FOUND = 'Testing if element <%s> is visible. ' +
|
||||
'Element could not be located.';
|
||||
|
||||
this.message = msg || util.format('Testing if element <%s> is visible.', selector);
|
||||
this.expected = true;
|
||||
|
||||
this.pass = function(value) {
|
||||
return value === this.expected;
|
||||
};
|
||||
|
||||
this.failure = function(result) {
|
||||
var failed = result === false || result && result.status === -1;
|
||||
if (failed) {
|
||||
this.message = msg || util.format(MSG_ELEMENT_NOT_FOUND, selector);
|
||||
}
|
||||
return failed;
|
||||
};
|
||||
|
||||
this.value = function(result) {
|
||||
return result.value;
|
||||
};
|
||||
|
||||
this.command = function(callback) {
|
||||
return this.api.isVisible(selector, callback);
|
||||
};
|
||||
|
||||
};
|
Reference in New Issue
Block a user