Skip to content

Commit

Permalink
Switch back again to Nightwatch ~3 on the 1.0.x branch #119
Browse files Browse the repository at this point in the history
  • Loading branch information
Natshah committed Jan 13, 2024
1 parent 21c24b4 commit 7b8c7b3
Showing 1 changed file with 22 additions and 47 deletions.
69 changes: 22 additions & 47 deletions lib/custom-assertions/elementContainsText.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down

0 comments on commit 7b8c7b3

Please sign in to comment.