diff --git a/lib/custom-assertions/elementContainsText.js b/lib/custom-assertions/elementContainsText.js index 6553ff1..af896ed 100755 --- a/lib/custom-assertions/elementContainsText.js +++ b/lib/custom-assertions/elementContainsText.js @@ -1,58 +1,33 @@ module.exports.assertion = function (negativeCase, expectedText, element) { - /** - * Returns the expected value of the assertion which is displayed in the case of a failure - * - * @return {string} - */ - browser.expected = function() { - return browser.negate ? `is not '${expectedText}'` : `is '${expectedText}'`; + this.message = `Testing if text of <${element}> ` + (negativeCase ? `does not contain '${expectedText}'` : `contains '${expectedText}'`); + + this.expected = function () { + return negativeCase ? `not contains '${expectedText}'` : `contains '${expectedText}'`; }; - - /** - * Given the value, the condition used to evaluate if the assertion is passed - * @param {*} value - * @return {Boolean} - */ - browser.evaluate = function(value) { - if (typeof value != 'string') { - return false; - } - - return value.includes(expectedText); + + this.evaluate = function (value) { + return (typeof value === 'string') && (value.includes(expectedText) !== negativeCase); }; - - /** - * When defined, browser method is called by the assertion runner with the command result to determine the actual - * state of the assertion in the event of a failure - * - * @param {Boolean} passed - * @return {string} - */ - browser.actual = function(passed) { - return passed ? `contains '${expectedText}'` : `does not contain '${expectedText}'`; + + this.value = function (result) { + return result.value; }; - /** - * The command which is to be executed by the assertion runner; Nightwatch api is available as browser.api - * @param {function} callback - */ - browser.command = function(callback) { - // Example: browser.api.getText(definition, callback); - - setTimeout(function() { - // The object containing a "value" property will be passed to the .value() method to determine the value w - // which is to be evaluated (by the .evaluate() method) - callback({ - value: '' - }); - - }, 1000); - - }; + this.command = function (callback) { + return this.api.getText(element, callback); + }; + + this.pass = function (value) { + return this.evaluate(value); + }; + + this.failure = function (result) { + return result === false || result && result.status === -1; + }; - browser.element('css selector', element, function (result) { + this.element('css selector', element, function (result) { if (result.status === 0) { if (negativeCase) { return browser.assert.not.textContains(element, expectedText).end();