import { CommonKeyword } from "./commonKeyword"; import { DewElement } from "./element"; import { DewLoader } from "./dewLoader"; import { logger } from "../Logger/logger"; import { lmt } from '../Helpers/readI18NProp'; import { Wait } from './dewWait'; import { TextField } from './textfield'; /** * Pagination Class */ export class DewPagination { /** * To navigate to specific page in the pagination * ```js * await DewPagination.goToPage("2") * @param {number}page */ static async goToPage(page: number) { try { await CommonKeyword.scrollIntoView(`.//input[@title='${await lmt.getLabel(`Gotopage`)}']`); await DewElement.verifyIfISeeElement(`.//input[@title='${await lmt.getLabel(`Gotopage`)}']`); await TextField.clearFieldenterTextUsingLocator(`.//input[@title='${await lmt.getLabel(`Gotopage`)}']`, page); await CommonKeyword.pressKey(`Enter`); await DewElement.verifyIfISeeElement(`.//div//button[contains(@class,'active')][text()='${page}']`); } catch (error) { logger.log(`Issue while performing operation in DDCC: Error while clicking on goto page of pagination`); throw error; } } /** * To show records per page * * ```js * await DewPagination.showRecordsPerPage(50) * ``` * * @param {number}page */ static async showRecordsPerPage(page: number) { try { await Wait.waitUntilVisibilityOfElement(`//dew-block`); const records = await DewElement.getNumberOfElementsPresentInDom(`(.//dew-col[dew-row[contains(@class,'list-body')]])[1]/dew-row[contains(@class,'list-body')]`); logger.info(`Total Number of record:`, records); if (await records <= 10 && page == 10) { logger.info(`Number of record Present is less than or equal to 10.Hence no option for pagination`); } else { await CommonKeyword.scrollIntoView(`.//dew-paginate//dew-dropdown-trigger[contains(@class,'dropdown')]`); await CommonKeyword.clickElement(`.//dew-paginate//dew-dropdown-trigger[contains(@class,'dropdown')]`); await Wait.waitUntilVisibilityOfElement(`.//div[contains(@class,'dropdown-menu show')]`); await CommonKeyword.clickElement(`.//div[contains(@class,'dropdown-menu show')]//div[text()[normalize-space()='${page}']]`); await Wait.waitForDefaultTimeout(5); await DewLoader.waitForSpinner(); await Wait.waitUntilVisibilityOfElement(`//dew-block`); const recordsAfter = await DewElement.getNumberOfElementsPresentInDom(`(//dew-col[dew-row[contains(@class,'list-body')]])[1]/dew-row[contains(@class,'list-body')]`); logger.info(recordsAfter); if (recordsAfter == page) { logger.info(`Records are displayed properly as defined`); } else { logger.info(`Records are not displayed as defined`); } } } catch (error) { logger.log(`Issue while performing operation in DDCC: Error while checking number of records in grid`); throw error; } await CommonKeyword.scrollPageToTop(); } /** * To navigate to next page * * ```js * * DewPagination.goToNextPage() * ``` * * * */ static async goToNextPage() { await CommonKeyword.clickElement(`.//button[@aria-label='naviagte to next page']`); } /** * To navigate to last page * * ```js * * DewPagination.goToLastPage() * ``` * * * */ static async goToLastPage() { await CommonKeyword.clickElement(`.//button[@aria-label='naviagte to last page']`); } /** * To navigate to previous page * * ```js * * DewPagination.goToPreviousPage() * ``` * * * */ static async goToPreviousPage() { await CommonKeyword.clickElement(`.//button[@aria-label='navigate to previous page']`); } /** * To go to the first page * * ```js * * DewPagination.goToFirstPage() * ``` * * * */ static async goToFirstPage() { await CommonKeyword.clickElement(`.//button[@aria-label='navigate to first page']`); } }