import { CommonKeyword } from "./commonKeyword"; import { lmt } from '../Helpers/readI18NProp'; import { logger } from '../Logger/logger'; import { DewElement } from "./element"; // const CommonKeyword = require("../components/commonKeyword") /** * Dew Checkbox class */ export class DewCheckbox { /** * To select all checkboxes in a checkbox collection * * ```js * * DewCheckbox.selectAll() * ``` * * * */ static async selectAll() { try { await CommonKeyword.click(`.//dew-checkbox/label[contains(text(),'${await lmt.getLabel(`SelectAll`)}')]`); await DewElement.verifyIfISeeCheckboxIsChecked(await lmt.getLabel(`SelectAll`)); } catch (error) { logger.log(`Issue while performing operation in DDCC: Error while selecting checkbox`); throw error; } } /** * To select a particular checkbox * * ```js * * DewCheckbox.selectCheckbox("Active") * ``` * * @param {String}checkboxName * */ static async selectCheckbox(checkboxName: string) { try { if (checkboxName === `SELECT ALL` || checkboxName == `Select All` || checkboxName == `select all`) { this.selectAll(); } await CommonKeyword.clickElement(`.//dew-checkbox[@title='${checkboxName}']/label | .//dew-row[dew-col//div[text()[normalize-space()='${checkboxName}']]]//input[@type='checkbox']/following-sibling::label | .//dew-checkbox/label[text()[normalize-space()='${checkboxName}']] | .//dew-row[dew-col/span[text()='${checkboxName}']]/dew-col/dew-checkbox | .//dew-row[contains(@class,'check-row')][dew-col//span[text()[normalize-space()='${checkboxName}']]]//input[@type='checkbox']/following-sibling::label | .//div[text()[normalize-space()='${checkboxName}']]/input`); } catch (error) { logger.log(`Issue while performing operation in DDCC: Error while selecting checkbox`); throw error; } } /** *  To select a row with checkbox as first column * * ```js * * DewCheckbox.selectCheckboxInRow() * ``` * * */ static async selectCheckboxInRow() { try { await CommonKeyword.clickElement(`(//dew-modal//dew-checkbox/label)[2]`); } catch (error) { logger.log(`Issue while performing operation in DDCC: Error while selecting checkbox`); throw error; } } /** *  To select checkbox at header level in grid * * ```js * * DewCheckbox.selectAllCheckboxInGrid() * ``` * * */ static async selectAllCheckboxInGrid() { try { await CommonKeyword.clickElement(`.//dew-modal//dew-row[contains(@class,'list-head')]//dew-checkbox | .//dew-tab[contains(@class,'d-block')]//dew-tab[contains(@class,'d-block')]/div[@class='custom-table-head']//dew-checkbox`); } catch (error) { logger.log(`Issue while performing operation in DDCC: Error while selecting checkbox`); throw error; } } }