import 'codeceptjs'; import { CommonKeyword } from './commonKeyword'; import { DewElement } from './element'; import { logger } from '../Logger/logger'; import { TextField } from './textfield'; import { Wait } from './dewWait'; import { GenerateRandom } from './generateRandom'; /** * AdditionalInformation Class * The class contains a method to fill custom fields */ export class AdditionalInformation extends Helper { /** * The method is used to fill Custom fields * ```js * await AdditionalInformation.fillCustomFields() * ``` */ static async fillCustomFields() { try { const tagArray = await getUniqueTagName(`//dew-tab[contains(@id,'additionalDetails')]//dew-row//dew-col/dew-input-container/div/*`); // To fill in field elements for await (const tagName of tagArray) { const fieldDefinitionElements = await `//dew-tab[contains(@id,'additionalDetails')]//dew-row//dew-col/dew-input-container/div//${tagName}`; if (await DewElement.getNumberOfElementsPresentInDom(fieldDefinitionElements) > 0) { console.log(`Filling Additional Custom field: ` + tagName); await customfill(tagName, fieldDefinitionElements); } } } catch (err) { throw err; } } } module.exports = new AdditionalInformation(); module.exports.AdditionalInformation = AdditionalInformation; // for inheritance /** * To get an array of elements * * await getElements(`//dew-file-upload//input[@type='file']`) * ``` * @param {String} locator */ async function getElements(locator: string) { const totalNumberOfElement = await DewElement.getNumberOfElementsPresentInDom(locator); let element: any; for (let index = 1; index <= totalNumberOfElement; index++) { const visibleElement: any = locate(locator); if (await DewElement.checkIfElementVisible(visibleElement)) { element = visibleElement.value; break; } } return element; } /** * The method return array of unique tagnames present in Additional Information * @param {String} locator */ async function getUniqueTagName(locator: string) { const fieldsList: Array = []; const flexiElements = await DewElement.getListOfElements(locator); for await (const element of flexiElements) { const grabTagName = await element.getTagName(); await fieldsList.push(`${grabTagName.toString()}`); } const uniqueTagArray = await [...new Set(fieldsList)]; return uniqueTagArray; } /** * * To fill custom fields / Additional fields * ```js * await AdditionalInformation.customfill("dew-elmdfield-autocomplete","//dew-elmdfield-autocomplete//input") * ``` * @param {string} tagName * @param {String} flexiLocator * */ async function customfill(tagName: string, flexiLocator: string) { await CommonKeyword.scrollIntoView(flexiLocator); const flexiElement = await getElements(flexiLocator); try { switch (tagName) { case `dew-elmdfield-autocomplete`: try { const autoCompleteLocator = flexiElement + `//input`; const noOfElements = await DewElement.getNumberOfElementsPresentInDom(autoCompleteLocator); for (let iterator = 1; iterator <= noOfElements; iterator++) { await CommonKeyword.scrollIntoView(`(` + autoCompleteLocator + `)` + `[${iterator}]`); for (let iterator = 1; iterator <= noOfElements; iterator++) { await CommonKeyword.scrollIntoView(`(` + autoCompleteLocator + `)` + `[${iterator}]`); await TextField.enterTextUsingLocator(`(` + autoCompleteLocator + `)` + `[${iterator}]`, ` `); const locator = `//div[@dew-autocomplete-body='']//div[contains(@class,'item')]`; await Wait.waitUntilVisibilityOfElement(locator); const autoCompleteElements = await DewElement.grabNumberOfVisibleElements(locator); const rnd = await GenerateRandom.generateRandomNumber(autoCompleteElements); await CommonKeyword.clickElement(`(//div[@dew-autocomplete-body='']//div[contains(@class,'item')])[${rnd + 1}]`); } } } catch (err) { logger.info(`Error in auto complete`); } break; default: throw new Error(`Error in DDCC`); } } catch (err) { throw err; } }