import { DewElement } from '../element'; import { logger } from '../../Logger/logger'; import { TextField } from '../textfield'; // import { Wait } from '../dewWait'; import { CommonKeyword } from '../commonKeyword'; import { ReadLocators } from "../../readLocators"; const locators:any = ReadLocators.readJson(); /** * Table Component for iSource */ export class TableComponent { /** * Method is used to enter the text in textfield present in table like structure * ```js * await TableComponent.enterText("Item Details","UOM","1","NewUOM") * ``` * @param {string} sectionName * @param {string} columnName * @param {string} rowNumber * @param {string} valueToEnter * */ static async enterText(sectionName: string, columnName: string, rowNumber: string, valueToEnter: string) { try { let grabbedText: string|string[]; let position: number = 0; const DynamicPath: string = await DewElement.getDynamicLocator(locators.iSourceSelectNameXpath, `<>`, sectionName); // await Wait.waitForDefaultTimeout(5); const elementCount = await DewElement.grabNumberOfVisibleElements(DynamicPath); console.log(`Total Matching element: ` + elementCount); // The below loop return the position of columnname for (let i = 1; i <= Number(elementCount); i++) { const DynamicPathinLoop: string = await DewElement.getDynamicLocator(locators.iSourceSubHeadNameXpath, `<>`, sectionName, `<>`, i.toString()); grabbedText = await DewElement.grabTextFrom(DynamicPathinLoop); console.log(`Position: ` + i + ` ` + grabbedText); // await Wait.waitForDefaultTimeout(2); if (grabbedText === columnName) { position = i; console.log((`position =` + position)); break; } } position = position + 1; const finalPath: string = await DewElement.getDynamicLocator(locators.iSourceSelectPositionXpath, `<>`, sectionName, `<>`, position.toString()); await CommonKeyword.scrollIntoView(await DewElement.getDynamicLocator(finalPath, `<>`, rowNumber)); await TextField.enterTextUsingLocator(await DewElement.getDynamicLocator(finalPath, `<>`, rowNumber), valueToEnter); } catch (err) { await logger.info(`Issue while performing operation in DDCC: Unable to Click element`); } } }