UNPKG

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

26 lines (24 loc) 1.22 kB
import waitForElementStateByIndex from "./waitForElementStateByIndex"; import {PageConfigTypes} from "../../../custom-types/pageConfig-types"; import {browser, $, $$, expect} from '@wdio/globals' import logger from "../../reporting-helpers/logger"; import he from "he"; export default async (elementPosition: number = 1, pageConfig: PageConfigTypes, elementState: string = "Existing"): Promise<string> => { const index = elementPosition - 1; let elementText = ""; await waitForElementStateByIndex(elementPosition, pageConfig, false, elementState, 0, 0) let elementsByIndex = await $$(pageConfig.selector)[index] if (await elementsByIndex.isDisplayed()) // elementText = await $(pageConfig.selector).getText(); elementText = await elementsByIndex.getText(); else { let htmlContent = await elementsByIndex.getHTML(); if (htmlContent.trim() == "") { // @ts-ignore htmlContent = await browser.execute((el) => el.textContent, elementsByIndex); } elementText = he.decode(htmlContent); } logger.info(`Element "${pageConfig.elementKey}" at position "${elementPosition}" has text "${elementText}"`); return elementText; };