import 'codeceptjs'; import { logger } from '../Logger/logger'; import { CommonKeyword } from './commonKeyword'; import { DewFileUpload } from './dewFileUpload'; import { DewLoader } from './dewLoader'; import { Wait } from './dewWait'; import { DewElement } from './element'; import { GenerateRandom } from './generateRandom'; import { TextField } from './textfield'; import { z } from './z'; const { I } = inject(); /** * Flexiform for eProc Class */ export class EForms { /** * The method is used to fill flexiform fields without using getInstance API call * * ```js * await eForms.eformWithoutAPI() * ``` */ static async eformWithoutAPI() { try { await DewLoader.waitForSpinner(); const locator = `//dew-section[@id='eform-section' or @id='eForm']//dew-common-eform//div/dew-row/dew-col/dew-input-container`; const elements = await DewElement.getNumberOfElementsPresentInDom(locator); console.log(`Total number of eform elements are : ${elements}`); if (await DewElement.getNumberOfElementsPresentInDom(locator + `//dew-file-upload//input[@type='file']`)) { const element = locator + `//dew-file-upload//input[@type='file']`; await fileUpload(element); } if (await DewElement.getNumberOfElementsPresentInDom(locator + `//input[@type='text' and not(@numeric | @placeholder)]`)) { const element = locator + `//input[@type='text' and not(@numeric | @placeholder)]`; await fillText(element); } if (await DewElement.getNumberOfElementsPresentInDom(locator + `//textarea`)) { const element = locator + `//textarea`; await fillTextArea(element); } if (await DewElement.getNumberOfElementsPresentInDom(locator + `//input[@type='text' and @numeric]`)) { const element = locator + `//input[@type='text' and @numeric]`; await fillNumeric(element); } if (await DewElement.getNumberOfElementsPresentInDom(locator + `//input[@placeholder="eForm URL"]`)) { const element = locator + `//input[@placeholder="eForm URL"]`; await fillURL(element); } if (await DewElement.getNumberOfElementsPresentInDom(locator + `//input[@aria-label='date' or contains(@class,'date-picker')]`)) { const element = locator + `//input[@aria-label='date' or contains(@class,'date-picker')]`; await fillDate(element); } if (await DewElement.getNumberOfElementsPresentInDom(locator + `//dew-dropdown-trigger`)) { const element = locator + `//dew-dropdown-trigger`; await fillDropDown(element); } if (await DewElement.getNumberOfElementsPresentInDom(locator + `[div//input[@type='checkbox']]`)) { const element = locator + `[div//input[@type='checkbox']]`; await selectCheckbox(element); } if (await DewElement.getNumberOfElementsPresentInDom(locator + `[div//input[@type='radio']]`)) { const element = locator + `[div//input[@type='radio']]`; await selectRadio(element); } } catch (err) { throw err; } } } module.exports = new EForms(); module.exports.EForms = EForms; // for inheritance /** * The method is used to select checkbox type field * @param {string} element */ async function selectCheckbox(element: string) { try { const noOfElements = await DewElement.getNumberOfElementsPresentInDom(element); for (let iterator = 1; iterator <= noOfElements; iterator++) { await CommonKeyword.scrollIntoView(`(` + element + `)` + `[${iterator}]`); await z.click(`(` + element + `)` + `[${iterator}]`); const checkboxLocator = await DewElement.getNumberOfElementsPresentInDom(`(` + `(` + element + `)` + `[${iterator}]` + `//input[not(contains(@class, 'hideInput'))])`); const rnd = await GenerateRandom.generateRandomNumber(checkboxLocator); await CommonKeyword.scrollIntoView(`(` + `(` + element + `)` + `[${iterator}]` + `//input[not(contains(@class, 'hideInput'))])[${rnd + 1}]`); await z.click(`(` + `(` + element + `)` + `[${iterator}]` + `//input[not(contains(@class, 'hideInput'))])[${rnd + 1}]`); } } catch (err) { logger.info(`Error in selecting checkbox`); } } /** * The method is used to select Radio button type field * @param {string} element */ async function selectRadio(element: string) { try { const noOfElements = await DewElement.getNumberOfElementsPresentInDom(element); for (let iterator = 1; iterator <= noOfElements; iterator++) { await CommonKeyword.scrollIntoView(`(` + element + `)` + `[${iterator}]`); await z.click(`(` + element + `)` + `[${iterator}]`); const radioLocator = await DewElement.getNumberOfElementsPresentInDom(`(` + `(` + element + `)` + `[${iterator}]` + `/div/label)`); const rnd = await GenerateRandom.generateRandomNumber(radioLocator); await CommonKeyword.scrollIntoView(`(` + `(` + element + `)` + `[${iterator}]` + `/div/label)[${rnd + 1}]`); await z.click(`(` + `(` + element + `)` + `[${iterator}]` + `/div/label)[${rnd + 1}]`); } } catch (err) { logger.info(`Error in selecting radio`); } } /** * The method is used to select Date and time * @param {string} dateTimeLocator */ async function fillDate(dateTimeLocator: string) { try { const noOfElements = await DewElement.getNumberOfElementsPresentInDom(dateTimeLocator); for (let iterator = 1; iterator <= noOfElements; iterator++) { console.log(`(` + dateTimeLocator + `)` + `[${iterator}]`); await CommonKeyword.scrollIntoView(`(` + dateTimeLocator + `)` + `[${iterator}]`); await z.click(`(` + dateTimeLocator + `)` + `[${iterator}]`); await z.click(`.currentDate`); } } catch (err) { logger.info(`Error in date-time`); } } /** * The method is used to select dropdown and multi-select type of field * @param {string} autoCompleteLocator */ async function fillDropDown(autoCompleteLocator: string) { try { const noOfElements = await DewElement.getNumberOfElementsPresentInDom(autoCompleteLocator); for (let iterator = 1; iterator <= noOfElements; iterator++) { await CommonKeyword.scrollIntoView(`(` + autoCompleteLocator + `)` + `[${iterator}]`); await z.click(`(` + autoCompleteLocator + `)` + `[${iterator}]`); const locator = `(//div[contains(@class,'dropdown-item')])`; await Wait.waitUntilVisibilityOfElement(locator); const autoCompleteElements = await DewElement.grabNumberOfVisibleElements(locator); const rnd = await GenerateRandom.generateRandomNumber(autoCompleteElements); await CommonKeyword.click(`(//div[contains(@class,'dropdown-item')])[${rnd + 1}]`); } } catch (err) { logger.info(`Error in auto complete`); } } /** * The method is used to enter random URL *@param {string} element */ async function fillURL(element: string) { try { const noOfElements = await DewElement.getNumberOfElementsPresentInDom(element); for (let iterator = 1; iterator <= noOfElements; iterator++) { await CommonKeyword.scrollIntoView(`(` + element + `)` + `[${iterator}]`); await TextField.enterTextUsingLocator(`(` + element + `)` + `[${iterator}]`, `https://` + await GenerateRandom.generateRandomString(8) + `.com`); } } catch (err) { logger.info(`Error in URL type field`); } } /** * The method is use to fill Numeeric type field * @param {string} element */ async function fillNumeric(element: string) { try { const noOfElements = await DewElement.getNumberOfElementsPresentInDom(element); for (let iterator = 1; iterator <= noOfElements; iterator++) { await CommonKeyword.scrollIntoView(`(` + element + `)` + `[${iterator}]`); await TextField.enterTextUsingLocator(`(` + element + `)` + `[${iterator}]`, await GenerateRandom.generateRandomNumber(8)); } } catch (err) { logger.info(`Error in Numeric type field`); } } /** * The method is use to fill textarea type field * @param {string} element */ async function fillTextArea(element: string) { try { const noOfElements = await DewElement.getNumberOfElementsPresentInDom(element); for (let iterator = 1; iterator <= noOfElements; iterator++) { await CommonKeyword.scrollIntoView(`(` + element + `)` + `[${iterator}]`); await TextField.enterTextUsingLocator(`(` + element + `)` + `[${iterator}]`, await GenerateRandom.generateRandomString(8)); } } catch (err) { logger.info(`Error in textarea type field`); } } /** * The method is use to upload a file *@param {string} element */ async function fileUpload(element: string) { const noOfElements = await DewElement.getNumberOfElementsPresentInDom(element); for (let iterator = 1; iterator <= noOfElements; iterator++) { await CommonKeyword.scrollIntoView(`(` + element + `)` + `[${iterator}]`); await DewFileUpload.uploadFileUsingLocator(`(` + element + `)` + `[${iterator}]`, `resources//Sprint.xlsx`); } } /** * The method is use to fill Text type field *@param {string} element */ async function fillText(element: string) { try { const noOfElements = await DewElement.getNumberOfElementsPresentInDom(element); for (let iterator = 1; iterator <= noOfElements; iterator++) { await CommonKeyword.scrollIntoView(`(` + element + `)` + `[${iterator}]`); await TextField.enterTextUsingLocator(`(` + element + `)` + `[${iterator}]`, await GenerateRandom.generateRandomString(8)); } } catch (err) { logger.info(`Error in text field`); } }