diff --git a/lib/api/assertions/elementsCount.js b/lib/api/assertions/elementsCount.js index 153cb9e416..189ef4b6ed 100644 --- a/lib/api/assertions/elementsCount.js +++ b/lib/api/assertions/elementsCount.js @@ -1,13 +1,13 @@ /** * Checks if the number of elements specified by a selector is equal to a given value. - * + * * @example - * + * * this.demoTest = function (browser) { * browser.assert.elementsCount('div', 10); * browser.assert.not.elementsCount('div', 10); * } - * + * * @method elementsCount * @param {string|object} definition The selector (CSS/Xpath) used to locate the element. Can either be a string or an object which specifies [element properties](https://nightwatchjs.org/guide#element-properties). * @param {string} count expected number of elements to be present. @@ -17,21 +17,21 @@ const Element = require('../../element'); -exports.assertion = function (definition, count, msg){ +exports.assertion = function (definition, count, msg) { this.options = { elementSelector: true }; this.expected = function() { - return this.negate ? `does not counts '${count}'` : `counts '${count}'`; + return this.negate ? `does not count ${count}` : `counts ${count}`; }; this.formatMessage = function() { - const message = msg || `Testing if the Element ${this.negate ? 'doesn\'t counts %s' : 'counts %s'}`; + const message = msg || `Testing if the element count for %s ${this.negate ? 'is not %s' : 'is %s'}`; return { message, - args: [this.elementSelector, `'${count}'`] + args: [this.elementSelector, count] }; }; @@ -45,7 +45,7 @@ exports.assertion = function (definition, count, msg){ } return result.value.length; - + }; this.createElement = function(selector, using = this.client.locateStrategy) { diff --git a/lib/api/assertions/textEquals.js b/lib/api/assertions/textEquals.js index 66775923c2..9803649845 100644 --- a/lib/api/assertions/textEquals.js +++ b/lib/api/assertions/textEquals.js @@ -47,7 +47,16 @@ exports.assertion = function(definition, expected, msg) { this.failure = function(result) { return result === false || result && result.status === -1; }; - + + this.actual = function(passed) { + const value = this.getValue(); + if (typeof value != 'string') { + return `Element does not have an innerText attribute`; + } + + return value; + }; + this.value = function(result) { if (result.status === -1) { return null; @@ -56,10 +65,6 @@ exports.assertion = function(definition, expected, msg) { return result.value; }; - this.actual = function(passed) { - return passed ? `equals '${expected}'` : `doesn't equal '${expected}'`; - }; - this.command = function(callback) { this.api.getText(setElementSelectorProps(definition, { suppressNotFoundErrors: true diff --git a/test/src/api/assertions/testTextEquals.js b/test/src/api/assertions/testTextEquals.js index 886be0ac83..82600f455c 100644 --- a/test/src/api/assertions/testTextEquals.js +++ b/test/src/api/assertions/testTextEquals.js @@ -39,7 +39,7 @@ describe('assert.textEquals', function () { assert.strictEqual(instance.hasFailure(), false); assert.strictEqual(instance.getValue(), 'other text'); - assert.strictEqual(instance.getActual(), 'doesn\'t equal \'text result\''); + assert.strictEqual(instance.getActual(), 'other text'); assert.strictEqual(instance.message, 'Test message'); } }); @@ -57,8 +57,8 @@ describe('assert.textEquals', function () { assert.strictEqual(queueOpts.negate, true); assert.strictEqual(instance.hasFailure(), false); assert.strictEqual(instance.getValue(), 'text result'); - assert.strictEqual(instance.getActual(), 'equals \'text result\''); - assert.strictEqual(err.message, `Test message in 5ms - expected "doesn't equal 'text result'" but got: "equals 'text result'" (${instance.elapsedTime}ms)`); + assert.strictEqual(instance.getActual(), 'text result'); + assert.strictEqual(err.message, `Test message in 5ms - expected "doesn't equal 'text result'" but got: "text result" (${instance.elapsedTime}ms)`); } }); }); @@ -74,7 +74,7 @@ describe('assert.textEquals', function () { assertion({instance, failure, message, err}) { assert.ok(message.startsWith('Testing if element\'s <.test_element> inner text equals \'text result\''), message); assert.deepStrictEqual(instance.options, {elementSelector: true}); - assert.strictEqual(instance.getActual(), 'equals \'text result\''); + assert.strictEqual(instance.getActual(), 'text result'); assert.strictEqual(instance.hasFailure(), false); assert.ok(message.startsWith('Testing if element\'s <.test_element> inner text equals \'text result\''), message); assert.strictEqual(failure, false); @@ -91,8 +91,8 @@ describe('assert.textEquals', function () { assertError: true, assertResult: true, assertion({instance, failure}) { - assert.strictEqual(instance.getActual(), 'doesn\'t equal \'text result\''); - assert.strictEqual(failure, 'Expected "equals \'text result\'" but got: "doesn\'t equal \'text result\'"'); + assert.strictEqual(instance.getActual(), 'not_expected'); + assert.strictEqual(failure, 'Expected "equals \'text result\'" but got: "not_expected"'); } }); });