import { lmt } from '../Helpers/readI18NProp'; import { logger } from '../Logger/logger'; import { CommonKeyword } from './commonKeyword'; import { DewElement } from './element'; import { TextField } from './textfield'; import { ReadLocators } from "../readLocators"; const locators:any = ReadLocators.readJson(); // import { Wait } from './dewWait'; /** * Information Card class */ export class InfoCard { /** * Fuction is use to check information card functionality * * ```js * * InfoCard.checkinfoCardFunctionality("//div"); * * ``` * @param {*} locatorParam located by Xpath|CSS * */ static async checkinfoCardFunctionality(locatorParam: any) { let locator: string; if (Array.isArray(locatorParam)) { locator = locatorParam[0]; } else { locator = locatorParam; } try { columnConfiguration(locator); const selectedColumn: string[] = await fetchColumName(); this.searchAndSelectCheckBox(selectedColumn); this.verfiyColumnInInfoCard(locator, selectedColumn); } catch (error) { logger.log(`Issue while performing operation in DDCC: Error while checking infocard functionality`); throw error; } } /** * Fuction is use to select Column in Information card * * ```js * * InfoCard.selectColumnInInfoCard("//div","Project Name"); * * ``` * @param {*} locatorParam located by Xpath|CSS * @param {String} columnName Column Name * */ static async selectColumnInInfoCard(locatorParam: any, columnName: string[]) { let locator: string; if (Array.isArray(locatorParam)) { locator = locatorParam[0]; } else { locator = locatorParam; } try { columnConfiguration(locator); this.searchAndSelectCheckBox(columnName); this.verfiyColumnInInfoCard(locator, columnName); } catch (error) { logger.log(`Issue while performing operation in DDCC: Error while selecting column in infocard`); throw error; } } /** * Search and Select checkbox in information card popup * * ```js * InfoCard.searchAndSelectCheckBox("Project Name") * ``` * * @param {String} selectedColumn Column Name */ static async searchAndSelectCheckBox(selectedColumn: string[]) { try { for (const columnName of selectedColumn) { await TextField.enterTextUsingLocator(locators.searchCheckBoxXpath, columnName); await CommonKeyword.clickElement(`.//dew-modal-body//div/dew-checkbox[label[text()[normalize-space()='${columnName}']]]`); await DewElement.verifyIfISeeCheckboxIsChecked(columnName); } await CommonKeyword.click(locators.searchCheckBoxApplyButtonXpath); } catch (error) { logger.log(`Issue while performing operation in DDCC: Error while selecting checkbox in inforcard`); throw error; } } /** * Function to verify column in information card * * ```js * InfoCard.verfiyColumnInInfoCard("//div","Project Name") * ``` * * @param {*} locatorParam located by xpath|CSS * @param {*} verfiyColumn Column name */ static async verfiyColumnInInfoCard(locatorParam: any, verfiyColumn: string[]) { let locator: string; if (Array.isArray(locatorParam)) { locator = locatorParam[0]; } else { locator = locatorParam; } try { await CommonKeyword.moveCursorTo(locator); await DewElement.verifyIfISeeElement(locators.verfiyColumnInInfoCardXpath); for (const columnName of verfiyColumn) { await DewElement.verifyIfISeeText(columnName); } } catch (error) { logger.log(`Issue while performing operation in DDCC: Error while verfying column in infocarrd`); throw error; } } } /** * To configure column * @param {*} locatorParam */ async function columnConfiguration(locatorParam: any) { let locator: string; if (Array.isArray(locatorParam)) { locator = locatorParam[0]; } else { locator = locatorParam; } try { await CommonKeyword.moveCursorTo(locator); await DewElement.verifyIfISeeElement(locators.verfiyColumnInInfoCardXpath); // await Wait.waitForDefaultTimeout(5); await CommonKeyword.clickElement(locators.infoCardColumnConfigurationXpath); await DewElement.verifyIfISeeText(`Column Configuration`); await CommonKeyword.clickElement(`.//dew-checkbox[label[text()[normalize-space()='${await lmt.getLabel(`SelectAll`)}']]]`); await CommonKeyword.clickElement(`.//dew-checkbox[label[text()[normalize-space()='${await lmt.getLabel(`SelectAll`)}']]]`); await DewElement.verifyIfISeeText(await lmt.getLabel(`Select_at_least`)); } catch (error) { logger.log(`Issue while performing operation in DDCC: Error while configuring column in infocard`); throw error; } } /** * To fetch Column Name */ async function fetchColumName() { try { const availableColumnName = await DewElement.grabTextFrom(locators.infoCardCheckboxLabelXpath); const selectedColumn = []; while (selectedColumn.length < 6) { const randomColumn = availableColumnName[Math.floor(Math.random() * availableColumnName.length)]; if (selectedColumn.indexOf(randomColumn) === -1) { selectedColumn.push(randomColumn); } } return selectedColumn; } catch (error) { logger.log(`Issue while performing operation in DDCC: Error while fetching column name from infocard`); throw error; } }