From 9c546e92e7937e670f3e31ed90f331bed901fbf3 Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Tue, 30 Apr 2024 15:32:00 +0200 Subject: [PATCH] @pages/BO/modules/moduleManager : Add router to go to the ModuleManager --- src/index.ts | 1 + .../BO/modules/moduleManager/selection.ts | 2 + src/interfaces/BO/router.ts | 6 +++ src/pages/BO/BOBasePage.ts | 31 ++++++++----- src/pages/BO/BORouterPage.ts | 35 +++++++++++++++ .../BO/modules/moduleManager/selection.ts | 5 ++- src/pages/FO/FOBasePage.ts | 4 +- .../BO/modules/moduleManager/selection.ts | 43 +++++++++++++++++++ .../BO/modules/moduleManager/selection.ts | 28 +++++++++--- .../pages/BO/modules/moduleManager/index.ts | 2 +- .../BO/modules/moduleManager/selection.ts | 11 +++++ 11 files changed, 148 insertions(+), 20 deletions(-) create mode 100644 src/interfaces/BO/router.ts create mode 100644 src/pages/BO/BORouterPage.ts create mode 100644 src/versions/1.7.3/pages/BO/modules/moduleManager/selection.ts diff --git a/src/index.ts b/src/index.ts index d82c6503..0444c315 100644 --- a/src/index.ts +++ b/src/index.ts @@ -184,6 +184,7 @@ export {default as FakerZone} from '@data/faker/zone'; export * as CommonPage from '@pages/commonPage'; // Export Pages BO export * as BOBasePage from '@pages/BO/BOBasePage'; +export {default as boRouterPage} from '@pages/BO/BORouterPage'; export {default as boLoginPage} from '@pages/BO/login'; export {default as boDashboardPage} from '@pages/BO/dashboard'; export {default as boDesignPositionsPage} from '@pages/BO/design/positions/index'; diff --git a/src/interfaces/BO/modules/moduleManager/selection.ts b/src/interfaces/BO/modules/moduleManager/selection.ts index 5541ac89..6784ac38 100644 --- a/src/interfaces/BO/modules/moduleManager/selection.ts +++ b/src/interfaces/BO/modules/moduleManager/selection.ts @@ -3,7 +3,9 @@ import type {Page} from '@playwright/test'; export interface ModuleManagerSelectionPageInterface extends BOBasePagePageInterface { readonly installMessageSuccessful: (moduleTag: string) => string; + readonly pageTitle: string; goToTabSelection(page: Page): Promise; + goToTabInstalledModules(page: Page): Promise; installModule(page: Page, moduleTag: string): Promise; } diff --git a/src/interfaces/BO/router.ts b/src/interfaces/BO/router.ts new file mode 100644 index 00000000..b88c9152 --- /dev/null +++ b/src/interfaces/BO/router.ts @@ -0,0 +1,6 @@ +import type {BOBasePagePageInterface} from '@interfaces/BO/index'; +import type {Frame, Page} from '@playwright/test'; + +export interface BORouterPageInterface extends BOBasePagePageInterface { + goToModuleManagerPage(page: Page): Promise; +} diff --git a/src/pages/BO/BOBasePage.ts b/src/pages/BO/BOBasePage.ts index 1e2e38e4..ca592cca 100644 --- a/src/pages/BO/BOBasePage.ts +++ b/src/pages/BO/BOBasePage.ts @@ -731,22 +731,31 @@ export default class BOBasePage extends CommonPage implements BOBasePagePageInte * @returns {Promise} */ async goToSubMenu(page: Page, parentSelector: string, linkSelector: string): Promise { - await this.clickSubMenu(page, parentSelector); - await this.scrollTo(page, linkSelector); - await this.clickAndWaitForURL(page, linkSelector); + const psVersion = testContext.getPSVersion(); - const shopVersion = testContext.getPSVersion(); let linkActiveClass: string = '-active'; - // >= 1.7.8.0 - if (semver.gte(shopVersion, '7.8.0')) { - linkActiveClass = 'link-active'; - } + // >= 1.7.4.0 + if (semver.gte(psVersion, '7.4.0')) { + await this.clickSubMenu(page, parentSelector); + await this.scrollTo(page, linkSelector); + await this.clickAndWaitForURL(page, linkSelector); - if (await this.isSidebarCollapsed(page)) { - await this.waitForHiddenSelector(page, `${linkSelector}.${linkActiveClass}`); + // >= 1.7.8.0 + if (semver.gte(psVersion, '7.8.0')) { + linkActiveClass = 'link-active'; + } + + if (await this.isSidebarCollapsed(page)) { + await this.waitForHiddenSelector(page, `${linkSelector}.${linkActiveClass}`); + } else { + await this.waitForVisibleSelector(page, `${linkSelector}.${linkActiveClass}`); + } } else { - await this.waitForVisibleSelector(page, `${linkSelector}.${linkActiveClass}`); + await page.locator(parentSelector).hover(); + await this.waitForVisibleSelector(page, linkSelector); + await this.clickAndWaitForURL(page, linkSelector); + await this.waitForVisibleSelector(page, `${parentSelector}.${linkActiveClass}`); } } diff --git a/src/pages/BO/BORouterPage.ts b/src/pages/BO/BORouterPage.ts new file mode 100644 index 00000000..9d3d76ad --- /dev/null +++ b/src/pages/BO/BORouterPage.ts @@ -0,0 +1,35 @@ +import {BORouterPageInterface} from '@interfaces/BO/router'; +import BOBasePage from '@pages/BO/BOBasePage'; +import boDashboardPage from '@pages/BO/dashboard/index'; +import boModuleManagerPage from '@pages/BO/modules/moduleManager/index'; +import boModuleManagerSelectionPage from '@pages/BO/modules/moduleManager/selection'; +import testContext from '@utils/testContext'; +import type {Page} from 'playwright-core'; +import semver from 'semver'; + +class BORouterPage extends BOBasePage implements BORouterPageInterface { + async goToModuleManagerPage(page: Page): Promise { + const psVersion = testContext.getPSVersion(); + const pageTitle = await this.getPageTitle(page); + const boModuleManagerLinkPageTitle = semver.lt(psVersion, '7.4.0') + ? boModuleManagerSelectionPage.pageTitle + : boModuleManagerPage.pageTitle; + + // Check if we are not already on the page + if (!pageTitle.includes(boModuleManagerLinkPageTitle)) { + await boDashboardPage.goToSubMenu( + page, + boDashboardPage.modulesParentLink, + boDashboardPage.moduleManagerLink, + ); + await boDashboardPage.closeSfToolBar(page); + } + + if (semver.lt(psVersion, '7.4.0')) { + console.log('goToTabInstalledModules'); + await boModuleManagerSelectionPage.goToTabInstalledModules(page); + } + } +} + +export default new BORouterPage(); diff --git a/src/pages/BO/modules/moduleManager/selection.ts b/src/pages/BO/modules/moduleManager/selection.ts index 452a04d0..bb746734 100644 --- a/src/pages/BO/modules/moduleManager/selection.ts +++ b/src/pages/BO/modules/moduleManager/selection.ts @@ -9,7 +9,10 @@ function requirePage(): ModuleManagerSelectionPageInterface { if (semver.gte(psVersion, '7.5.0')) { return require('@versions/mock/pages/BO/modules/moduleManager/selection'); } - return require('@versions/1.7.4/pages/BO/modules/moduleManager/selection'); + if (semver.gte(psVersion, '7.4.0')) { + return require('@versions/1.7.4/pages/BO/modules/moduleManager/selection').selectionPage; + } + return require('@versions/1.7.3/pages/BO/modules/moduleManager/selection'); } /* eslint-enable global-require, @typescript-eslint/no-var-requires */ diff --git a/src/pages/FO/FOBasePage.ts b/src/pages/FO/FOBasePage.ts index 7a2b4cbc..f37611ab 100644 --- a/src/pages/FO/FOBasePage.ts +++ b/src/pages/FO/FOBasePage.ts @@ -1,7 +1,7 @@ // Import pages import {FOBasePagePageInterface} from '@interfaces/FO'; import CommonPage from '@pages/commonPage'; -import testContext from '@utils/testContext'; +import utilsTest from '@utils/test'; import type {Locator, Page} from 'playwright'; import semver from 'semver'; @@ -792,7 +792,7 @@ export default class FOBasePage extends CommonPage implements FOBasePagePageInte } private getLanguageSelector(page: Page, lang: string): string|Locator { - const psVersion = testContext.getPSVersion(); + const psVersion = utilsTest.getPSVersion(); // >= 1.7.5.0 if (semver.gte(psVersion, '7.5.0')) { diff --git a/src/versions/1.7.3/pages/BO/modules/moduleManager/selection.ts b/src/versions/1.7.3/pages/BO/modules/moduleManager/selection.ts new file mode 100644 index 00000000..356bec0c --- /dev/null +++ b/src/versions/1.7.3/pages/BO/modules/moduleManager/selection.ts @@ -0,0 +1,43 @@ +import {ModuleManagerSelectionPageInterface} from '@interfaces/BO/modules/moduleManager/selection'; +import {Page} from '@playwright/test'; +import {SelectionPage} from '@versions/1.7.4/pages/BO/modules/moduleManager/selection'; + +/** + * @class + * @extends BOBasePage + */ +class SelectionPageVersion extends SelectionPage implements ModuleManagerSelectionPageInterface { + /** + * @constructs + * Setting up titles and selectors to use on module catalog page + */ + constructor() { + super(); + + // Selectors + this.subTabSelection = '#head_tabs a.tab:nth-child(1)'; + this.subTabInstalledModules = '#head_tabs a.tab:nth-child(2)'; + } + + /** + * Go to the "Selection" tab + * @param {Page} page + * @returns {Promise} + */ + async goToTabSelection(page: Page): Promise { + await this.waitForSelectorAndClick(page, this.subTabSelection); + await this.waitForVisibleSelector(page, `${this.subTabSelection}.current`, 2000); + } + + /** + * Go to the "Installed Modules" tab + * @param {Page} page + * @returns {Promise} + */ + async goToTabInstalledModules(page: Page): Promise { + await this.waitForSelectorAndClick(page, this.subTabInstalledModules); + await this.waitForVisibleSelector(page, `${this.subTabInstalledModules}.current`, 2000); + } +} + +module.exports = new SelectionPageVersion(); diff --git a/src/versions/1.7.4/pages/BO/modules/moduleManager/selection.ts b/src/versions/1.7.4/pages/BO/modules/moduleManager/selection.ts index f8bfb15e..fdcca393 100644 --- a/src/versions/1.7.4/pages/BO/modules/moduleManager/selection.ts +++ b/src/versions/1.7.4/pages/BO/modules/moduleManager/selection.ts @@ -7,9 +7,13 @@ import {Page} from '@playwright/test'; * @extends BOBasePage */ class SelectionPage extends BOBasePage implements ModuleManagerSelectionPageInterface { + public readonly pageTitle: string; + public readonly installMessageSuccessful: (moduleTag: string) => string; - private readonly subTabUninstalledModules: string; + protected subTabSelection: string; + + protected subTabInstalledModules: string; private readonly searchInput: string; @@ -24,10 +28,13 @@ class SelectionPage extends BOBasePage implements ModuleManagerSelectionPageInte constructor() { super(); + this.pageTitle = 'Module selection'; + this.installMessageSuccessful = (moduleTag: string) => `Install action on module ${moduleTag} succeeded.`; // Selectors - this.subTabUninstalledModules = '#subtab-AdminModulesCatalog'; + this.subTabSelection = '#subtab-AdminModulesCatalog'; + this.subTabInstalledModules = '#subtab-AdminModulesManage'; this.searchInput = '#search-input-group input.pstaggerAddTagInput'; this.searchButton = '#module-search-button'; this.installModuleButton = (moduleTag: string) => `div[data-tech-name="${moduleTag}"] button.module_action_menu_install`; @@ -42,8 +49,18 @@ class SelectionPage extends BOBasePage implements ModuleManagerSelectionPageInte * @returns {Promise} */ async goToTabSelection(page: Page): Promise { - await this.waitForSelectorAndClick(page, this.subTabUninstalledModules); - await this.waitForVisibleSelector(page, `${this.subTabUninstalledModules}.active`, 2000); + await this.waitForSelectorAndClick(page, this.subTabSelection); + await this.waitForVisibleSelector(page, `${this.subTabSelection}.active`, 2000); + } + + /** + * Go to the "Selection" tab + * @param {Page} page + * @returns {Promise} + */ + async goToTabInstalledModules(page: Page): Promise { + await this.waitForSelectorAndClick(page, this.subTabInstalledModules); + await this.waitForVisibleSelector(page, `${this.subTabInstalledModules}.active`, 2000); } /** @@ -62,4 +79,5 @@ class SelectionPage extends BOBasePage implements ModuleManagerSelectionPageInte } } -module.exports = new SelectionPage(); +const selectionPage = new SelectionPage(); +export {selectionPage, SelectionPage}; diff --git a/src/versions/develop/pages/BO/modules/moduleManager/index.ts b/src/versions/develop/pages/BO/modules/moduleManager/index.ts index fd931718..2a15a680 100644 --- a/src/versions/develop/pages/BO/modules/moduleManager/index.ts +++ b/src/versions/develop/pages/BO/modules/moduleManager/index.ts @@ -440,7 +440,7 @@ class ModuleManagerPage extends BOBasePage implements ModuleManagerPageInterface if (cancel) { await this.waitForSelectorAndClick(page, this.modalConfirmCancel(module.tag, action)); - await this.elementNotVisible(page, this.modalConfirmAction(module.tag, action), 10000); + await this.waitForHiddenSelector(page, this.modalConfirmAction(module.tag, action), 10000); return ''; } if (action === 'uninstall' && forceDeletion) { diff --git a/src/versions/mock/pages/BO/modules/moduleManager/selection.ts b/src/versions/mock/pages/BO/modules/moduleManager/selection.ts index 7d6d12ea..a4bfdd2f 100644 --- a/src/versions/mock/pages/BO/modules/moduleManager/selection.ts +++ b/src/versions/mock/pages/BO/modules/moduleManager/selection.ts @@ -7,6 +7,8 @@ import BOBasePage from '@pages/BO/BOBasePage'; * @extends BOBasePage */ class SelectionPageMock extends BOBasePage implements ModuleManagerSelectionPageInterface { + public readonly pageTitle: string; + public readonly installMessageSuccessful: (moduleTag: string) => string; /** @@ -16,6 +18,7 @@ class SelectionPageMock extends BOBasePage implements ModuleManagerSelectionPage constructor() { super(); + this.pageTitle = ''; this.installMessageSuccessful = () => ''; } @@ -30,6 +33,14 @@ class SelectionPageMock extends BOBasePage implements ModuleManagerSelectionPage // do nothing. } + /** + * Go to the "Installed Modules" tab + * @returns {Promise} + */ + async goToTabInstalledModules(): Promise { + // do nothing. + } + /** * Install the module and return if installed * @returns {Promise}