import { DewNavBar } from "./dewNavBar"; // import { DewLoader } from "./dewLoader"; import { DewElement } from './element'; import { CommonKeyword } from './commonKeyword'; // import { DewButton } from './dewButton'; import { Wait } from './dewWait'; import { Tab } from './tab'; import { DewLoader } from "./dewLoader"; import { DewButton } from "./dewButton"; /** * Side Menu Navigation */ export class ProductNavigator { /** * To navigate to a particular product's page * * ```js * await ProductNavigator.navigate("TMS"); * await ProductNavigator.navigate("iSupplier","Suppliers"); * await ProductNavigator.navigate("iSupplier", "Settings", "Manage Users"); * ``` * * @param {string} product * @param {...string} tab 1 to n number of tabs * */ static async navigate(product: string, ...tab: string[]) { // Click Product link try { await CommonKeyword.dismissNotification(); await DewNavBar.openHamburger(); await Wait.waitUntilVisibilityOfElement(`.//dew-side-menu//ul[1]//li[contains(@class,'menu-item')]`); await CommonKeyword.scrollIntoView(`.//dew-side-menu//ul[1]//li[contains(@class,'menu-item') and @title[normalize-space()="${product}"]]`); const isSelected = await DewElement.checkIfElementVisible(`.//dew-side-menu//ul[1]//li[contains(@class,'menu-item') and contains(@class,'active') and @title[normalize-space()="${product}"]]|.//dew-side-menu//ul[1]//li[contains(@class,'menu-item') and contains(@class,'menu-highlight') and @title[normalize-space()="${product}"]]`); if (isSelected != true) { await CommonKeyword.clickElement(`.//dew-side-menu//ul[1]//li[contains(@class,'menu-item') and @title="${product}"]`); } //below code will check if last argument is a number //if yes, then will set the timeout and limit accordingly //else timeout will remain undefined, and limit will be set as the length of the tab array let timeout: any; let limit = tab.length; let flag = isNaN(parseInt(tab[tab.length - 1])); if(!flag) { limit = tab.length - 1; timeout = tab[limit]; } // Verify if the next level menu is opened, if applicable for (let index = 0; index < limit; index++) { await Wait.waitUntilVisibilityOfElement(`.//dew-side-menu//ul[${(index + 2)}]//li[contains(@class,'menu-item')]`); const isSelected = await DewElement.checkIfElementVisible(`.//dew-side-menu//ul[${(index + 2)}]//li[contains(@class,'menu-item') and contains(@class,'active') and @title[normalize-space()="${tab[index]}"]]`); if (isSelected != true) { await CommonKeyword.clickElement(`.//dew-side-menu//ul[${(index + 2)}]//li[contains(@class,'menu-item') and @title[normalize-space()="${tab[index]}"]]`); } } await DewLoader.waitToProcess(timeout); await DewLoader.waitForProgressLoader(timeout); await DewLoader.waitForSpinner(timeout); if (await DewElement.checkIfElementVisible(`.//dew-btn/button[div/span[text()[normalize-space()='Continue']]]`)) { await DewButton.click(`Continue`); } await CommonKeyword.dismissNotification(); } catch (error) { console.log(`Error While Navigation`); throw error; } } /** * To navigate to a particular module in ZSN * ```js * await ProductNavigator.navigate("Test_92","My Invoices","Create PO Invoice","ZCS") * ``` * @param {*} testName * @param {*} product * @param {*} tab * @param {*} subTab * */ static async navigateZSN(testName: string, product: string, tab: string, subTab: string) { session(testName, async () => { // Click Product link await CommonKeyword.moveCursorTo(`.//*[@id='zsp-submenus-id']//a//span[text()='${product}']`); await CommonKeyword.clickElement(`.//*[@id='zsp-submenus-id']//a//span[text()='${product}']`); await CommonKeyword.moveCursorTo(`.//*[@id='zsp-submenus-id']//ul/li[span[text()='${product}']]/following-sibling::li//span[text()='${tab}']`); await CommonKeyword.clickElement(`.//*[@id='zsp-submenus-id']//ul/li[span[text()='${product}']]/following-sibling::li//span[text()='${tab}']`); await CommonKeyword.moveCursorTo(`.//*[@id='zsp-submenus-id']//ul/li[span[text()='${product}']]/following-sibling::li/a[span/span[text()='${tab}']]/following-sibling::ul//span[text()='${subTab}']`); await CommonKeyword.clickElement(`.//*[@id='zsp-submenus-id']//ul/li[span[text()='${product}']]/following-sibling::li/a[span/span[text()='${tab}']]/following-sibling::ul//span[text()='${subTab}']`); }); } /** *  To check if specified module is present in SideBar Menu * * ```js * await ProductNavigator.checkIfModulePresent("iSupplier") * ``` * * @param {string}product */ static async checkIfModulePresent(product: string) { // Click Product link await DewElement.verifyIfISeeElement(`.//dew-side-menu//ul[1]/li[contains(@class,'menu-item') and @title='${product}']`); } /** * This function is used to check if page is navigate to specified product * @param {string} product */ static async checkIfNavigatedToSpecifiedProduct(product: string) { // Click Product link await DewElement.verifyIfISeeInCurrentUrl(product); } /** * To check if page is navigate to specified product * * ```js * await ProductNavigator.checkIfNavigatedToSpecifiedProduct("iSupplier") * ``` * * @param {string}product */ static async checkIfModuleOpenedInNewtab(product: string) { await Tab.switchToNextTab(); await DewElement.verifyIfISeeInCurrentUrl(product); } }