@nice-digital/wdio-cucumber-steps
Version:
Shared step definitions for Cucumber JS BDD tests in WebdriverIO
39 lines • 1.56 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkContainsText = void 0;
/*! https://github.com/webdriverio/cucumber-boilerplate/blob/master/src/support/check/checkContainsText.js */
/**
* Check if the given elements contains text
* @param {String} elementType Element type (element or button)
* @param {String} selector Element selector
* @param {String} falseCase Whether to check if the content contains
* the given text or not
* @param {String} expectedText The text to check against
*/
async function checkContainsText(elementType, selector, falseCase, expectedText) {
const element = await $(selector), elementValueAttr = (await element.getAttribute("value"));
let command = "getValue";
if (["button", "container"].includes(elementType) ||
elementValueAttr === null) {
command = "getText";
}
let boolFalseCase;
let stringExpectedText = expectedText;
await element.waitForDisplayed();
const text = await element[command]();
if (typeof expectedText === "undefined") {
stringExpectedText = falseCase;
boolFalseCase = false;
}
else {
boolFalseCase = falseCase === " not";
}
if (boolFalseCase) {
expect(text).not.toContain(stringExpectedText);
}
else {
expect(text).toContain(stringExpectedText);
}
}
exports.checkContainsText = checkContainsText;
//# sourceMappingURL=checkContainsText.js.map