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
41 lines (35 loc) • 2.15 kB
text/typescript
import {ConfigHelper} from "../../common-helpers/config-helper";
import {PageConfigTypes} from "../../../custom-types/pageConfig-types";
import {CustomExpect} from "../../common-helpers/custom-expect";
import {browser, $, $$, expect} from '@wdio/globals'
/**
* Check if the given elements text is the same as the given text
* @param elementType button | element | field
* @param pageConfig
* @param {String} falseCase Whether to check if the content equals the
* given text or not
* @param {String} expectedText The text to validate against
*
* Therefore you can use getText on DOM-elements such as a <div> or a <p> or <a>. However,
* if it is an <input> field or <textarea>, <select> then you would need to use the getValue command.
* @param ignoreCaseCheck
*/
export default async function (elementType: string, pageConfig: PageConfigTypes, falseCase: boolean, expectedText: string, ignoreCaseCheck = false) {
let text;
const elem = $(pageConfig.selector);
await elem.waitForDisplayed();
if (ignoreCaseCheck)
expectedText = expectedText.toLowerCase();
if (elementType.trim() !== 'button' && elementType.trim() !== 'element' && elementType.trim() !== 'field')
throw new Error(`Invalid selection for "CheckEqualsText" function. Valid selection is "button | element | field"`);
if (elementType.trim() == 'button' || elementType.trim() == 'element') {
text = ignoreCaseCheck ? (await elem.getText()).toLowerCase() : (await elem.getText());
} else if (elementType.trim() == 'field') {
text = ignoreCaseCheck ? (await elem.getValue()).toLowerCase() : (await elem.getValue());
}
if (falseCase) {
CustomExpect.expectNotToBe(expectedText, text, `Expected Text/Value of element "${pageConfig.pageId}.${pageConfig.elementKey}" "${expectedText}" is matching with actual Text/Value "${text}"`);
} else {
CustomExpect.expectToBe(expectedText, text, `Expected Text/Value of element "${pageConfig.pageId}.${pageConfig.elementKey}" "${expectedText}" is not matching with actual Text/Value "${text}"`);
}
};