import { z } from './z'; import { CommonKeyword } from './commonKeyword'; import { DewElement } from './element'; const { I } = inject(); /** * Text field class */ export class TextField { /** * To enter text in text field * * ```js * * TextField.enterText("Project Name","Project_123"); * ``` * * @param {String} fieldLbl //Label of the input box * @param {String} valueToEnter // Value you want to enter into the text box * */ static async enterText(fieldLbl: string, valueToEnter: string | number) { await z.fillField(`.//p[contains(.,'${fieldLbl}')]/following-sibling::p/input| .//*[label[div[contains(.,'${fieldLbl}')]]]//input[not(contains(@class,'hideInput'))]`, valueToEnter.toString()); } /** * To enter text in text field using the placeholder attribute * * ``js * TextField.enterTextUsingPlaceHolder("Enter Project Name","Project_123"); * ``` * * @param {String} placeholder // input Box placeholder * @param {String} valueToEnter //Value to enter into the textbox * */ static async enterTextUsingPlaceHolder(placeholder: string, valueToEnter: string | number) { // const element = await DewElement.getVisibleElement(`.//input[@placeholder[normalize-space()='${placeholder}']]`); // await DewElement.verifyIfISeeElement(element); // // await z.seeElement(element); // await z.clearField(element); await z.fillField(`.//input[@placeholder[normalize-space()='${placeholder}']]`, valueToEnter.toString()); } /** * To enter text in text field by passing locator * * ``js * TextField.enterTextUsingLocator("//input[@id='emailID']","Project_123"); * ``` * * @param {String} locator located by xpath | CSS * @param {String} dataToFill //Value to enter into the textbox * */ static async enterTextUsingLocator(locator: string, dataToFill: string | number) { // await DewElement.verifyIfISeeElement(locator); // const visibleElement = await DewElement.getVisibleElement(locator); // await z.clearField(visibleElement); await z.fillField(locator, dataToFill.toString()); // await z.seeInField(locator, dataToFill); } /** * To enter text in text field by passing locator * * ``js * TextField.enterTextUsingLocator("//input[@id='emailID']","Project_123"); * ``` * * @param {String} locator located by xpath | CSS * @param {String} dataToFill //Value to enter into the textbox * */ static async clearFieldenterTextUsingLocator(locator: string, dataToFill: string | number) { // await DewElement.verifyIfISeeElement(locator); // const visibleElement = await DewElement.getVisibleElement(locator); // await z.executeScript(` // var elFrom = document.evaluate("${visibleElement}", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue // elFrom.value=""; // `, visibleElement); await z.fillField(locator, dataToFill.toString()); // await z.seeInField(locator, dataToFill); } /** * Types out the given string or the array of keys provided. * * ```js * When passing in a string * await Textfield.type('//div/input','Type this out.'); * * When passing in an array * await Textfield.type('//div/input',['T', 'E', 'X', 'T']); * ``` * * @param { string } locator xpath of the input box * @param {string | Array } key or array of keys to type. Type out given array of keys or a string of text * */ static async type(locator: string, key: string | Array) { await CommonKeyword.clickWrapper(locator); await z.type(key); } /** * Types out the given text into an active field. * * ```js * When passing in a string * await Textfield.typeText('Type this out.'); * * When passing in an array * await Textfield.typeText(['T', 'E', 'X', 'T']); * ``` * * @param {string | Array } key or array of keys to type. Type out given array of keys or a string of text * */ static async typeText(key: string | Array) { await z.type(key); } } module.exports = new TextField(); module.exports.TextField = TextField;