tlc-core-automation-framework-v3-wdio-v9
Version:
Background: - We are following multi-layer automation framework architecture using webdriver.io + cucumber + typescript This core framework has been implemented with generic utility functions and cucumber steps, which can be easily consumed by another fra
42 lines (38 loc) • 2.07 kB
text/typescript
import {PageConfigTypes} from "../../../custom-types/pageConfig-types";
import {CustomExpect} from "../../common-helpers/custom-expect";
import {browser, $, $$, expect} from '@wdio/globals'
import getElementText from "../action/getElementText";
/**
* Check if the given elements contains text
* @param pageConfig
* @param {String} falseCase Whether to check if the content contains
* the given text or not
* @param {String} expectedText The text to check against
* @param ignoreCaseCheck
*/
export default async function (pageConfig: PageConfigTypes, falseCase: boolean, expectedText: string, ignoreCaseCheck = false) {
// const elem = await $(pageConfig.selector);
// await elem.waitForDisplayed();
// // const text = await elem.getText();
// const text = await elem.getHTML();
//
// const htmlContent = await $(pageConfig.selector).getHTML();
// const htmlText = htmlContent.replace(/<\/?[^>]+(>|$)/g, "").trim();
// const elementText = he.decode(htmlText);
//
// if (falseCase) {
// CustomExpect.expectNotToContain(text, expectedText, `Element "${pageConfig.pageId}.${pageConfig.elementKey}" contains text "${expectedText}"`)
// } else {
// CustomExpect.expectToContain(text, expectedText, `Element "${pageConfig.pageId}.${pageConfig.elementKey}" does not contain text "${expectedText}"`)
// }
let actualElementText = await getElementText(pageConfig);
if (ignoreCaseCheck) {
actualElementText = actualElementText.toLowerCase();
expectedText = expectedText.toLowerCase();
}
if (falseCase) {
CustomExpect.expectNotToContain(actualElementText, expectedText, `Element "${pageConfig.pageId}.${pageConfig.elementKey}" contains text "${expectedText}", text found : "${actualElementText}"`)
} else {
CustomExpect.expectToContain(actualElementText, expectedText, `Element "${pageConfig.pageId}.${pageConfig.elementKey}" does not contain text "${expectedText}", text found : "${actualElementText}"`)
}
};