import { DewElement } from '../element'; import { logger } from '../../Logger/logger'; import { TextField } from '../textfield'; // import { Wait } from '../dewWait'; import { CommonKeyword } from '../commonKeyword'; /** * 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(`//dew-section[dew-flex/dew-flex-item[div[contains(.,'<>')]]]//dew-block//dew-col/span[@class='text-subhead-b']`, `<>`, 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(`(//dew-section[dew-flex/dew-flex-item[div[contains(.,'<>')]]]//dew-block//dew-col/span[@class='text-subhead-b'])[<>]`, `<>`, 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(`((//dew-section[dew-flex/dew-flex-item[div[contains(.,'<>')]]]//dew-block//dew-col/span[@class='text-subhead-b']/ancestor::dew-row)[2]/following-sibling::div/dew-row[<>]/dew-col)[<>]/input`, `<>`, 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`); } } }