@nice-digital/wdio-cucumber-steps
Version:
Shared step definitions for Cucumber JS BDD tests in WebdriverIO
38 lines • 1.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkEqualsText = void 0;
/**
* Check if the given elements text is the same as the given text
* @param {String} elementType Element type (element or button)
* @param {String} selector Element selector
* @param {String} falseCase Whether to check if the content equals the
* given text or not
* @param {String} expectedText The text to validate against
*/
async function checkEqualsText(elementType, selector, falseCase, expectedText) {
const element = await $(selector), elementValueAttr = (await element.getAttribute("value"));
let command = "getValue";
if (elementType === "button" || elementValueAttr === null) {
command = "getText";
}
let parsedExpectedText = expectedText;
let boolFalseCase = !!falseCase;
// Check for empty element
if (typeof parsedExpectedText === "function") {
parsedExpectedText = "";
boolFalseCase = !boolFalseCase;
}
if (parsedExpectedText === undefined && falseCase === undefined) {
parsedExpectedText = "";
boolFalseCase = true;
}
const text = await element[command]();
if (boolFalseCase) {
expect(text).not.toBe(parsedExpectedText);
}
else {
expect(text).toBe(parsedExpectedText);
}
}
exports.checkEqualsText = checkEqualsText;
//# sourceMappingURL=checkEqualsText.js.map