From 9fc24e227003b512a592b9eaf35285de1528feca Mon Sep 17 00:00:00 2001 From: nesrineabdmouleh Date: Thu, 7 Nov 2024 14:47:33 +0100 Subject: [PATCH 1/2] Migrate 173 selectors --- src/pages/BO/BOBasePage.ts | 70 ++++++++++--------- src/pages/BO/catalog/products/create/index.ts | 3 + src/pages/BO/catalog/products/index.ts | 3 + .../pages/BO/catalog/products/create/index.ts | 35 ++++++++++ .../1.7.3/pages/BO/catalog/products/index.ts | 35 ++++++++++ .../pages/BO/catalog/products/create/index.ts | 2 +- .../pages/BO/catalog/products/index.ts | 1 + 7 files changed, 115 insertions(+), 34 deletions(-) create mode 100644 src/versions/1.7.3/pages/BO/catalog/products/create/index.ts create mode 100644 src/versions/1.7.3/pages/BO/catalog/products/index.ts diff --git a/src/pages/BO/BOBasePage.ts b/src/pages/BO/BOBasePage.ts index bbeccc07..923587b6 100644 --- a/src/pages/BO/BOBasePage.ts +++ b/src/pages/BO/BOBasePage.ts @@ -617,7 +617,7 @@ export default class BOBasePage extends CommonPage implements BOBasePagePageInte // Symfony Toolbar this.sfToolbarMainContentDiv = "div[id*='sfToolbarMainContent']"; - this.sfCloseToolbarLink = "[id*='sfToolbarHideButton']"; + this.sfCloseToolbarLink = "[id*='sfToolbarHideButton'], a.hide-button"; // Sidebar this.rightSidebar = '#right-sidebar'; @@ -638,7 +638,7 @@ export default class BOBasePage extends CommonPage implements BOBasePagePageInte * @param page {Page} Browser tab * @returns {Promise} */ - async getShopVersion(page:Page):Promise { + async getShopVersion(page: Page): Promise { return this.getTextContent(page, this.shopVersion); } @@ -737,22 +737,26 @@ 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 shopVersion = testContext.getPSVersion(); - let linkActiveClass: string = '-active'; - - // >= 1.7.8.0 - if (semver.gte(shopVersion, '7.8.0')) { - linkActiveClass = 'link-active'; - } - - if (await this.isSidebarCollapsed(page)) { - await this.waitForHiddenSelector(page, `${linkSelector}.${linkActiveClass}`); + if (semver.lt(shopVersion, '7.4.0')) { + await page.hover(parentSelector); + await this.clickAndWaitForURL(page, linkSelector); } else { - await this.waitForVisibleSelector(page, `${linkSelector}.${linkActiveClass}`); + await this.clickSubMenu(page, parentSelector); + await this.scrollTo(page, linkSelector); + await this.clickAndWaitForURL(page, linkSelector); + let linkActiveClass: string = '-active'; + + // >= 1.7.8.0 + if (semver.gte(shopVersion, '7.8.0')) { + linkActiveClass = 'link-active'; + } + + if (await this.isSidebarCollapsed(page)) { + await this.waitForHiddenSelector(page, `${linkSelector}.${linkActiveClass}`); + } else { + await this.waitForVisibleSelector(page, `${linkSelector}.${linkActiveClass}`); + } } } @@ -998,14 +1002,14 @@ export default class BOBasePage extends CommonPage implements BOBasePagePageInte const args = {selector: iFrameSelector, vl: value, hasP: hasParagraph}; // eslint-disable-next-line no-eval const fn: { fnSetValueOnTinymceInput: PageFunction<{ selector: string, vl: string, hasP: boolean }, void> } = eval(`({ - async fnSetValueOnTinymceInput(args) { - /* eslint-env browser */ - const iFrameElement = await document.querySelector(args.selector); - const iFrameHtml = iFrameElement.contentDocument.documentElement; - const textElement = await iFrameHtml.querySelector(args.hasP ? 'body p' : 'body'); - textElement.textContent = args.vl; - } - })`); + async fnSetValueOnTinymceInput(args) { + /* eslint-env browser */ + const iFrameElement = await document.querySelector(args.selector); + const iFrameHtml = iFrameElement.contentDocument.documentElement; + const textElement = await iFrameHtml.querySelector(args.hasP ? 'body p' : 'body'); + textElement.textContent = args.vl; + } + })`); await page.evaluate(fn.fnSetValueOnTinymceInput, args); } @@ -1031,15 +1035,15 @@ export default class BOBasePage extends CommonPage implements BOBasePagePageInte const args = {selector, value, onChange}; // eslint-disable-next-line no-eval const fn: { fnSetValueOnDTPickerInput: PageFunction<{ selector: string, value: string, onChange: boolean }, void> } = eval(`({ - async fnSetValueOnDTPickerInput(args) { - /* eslint-env browser */ - const textElement = await document.querySelector(args.selector); - textElement.value = args.value; - if (args.onChange) { - textElement.dispatchEvent(new Event('change')); - } - } - })`); + async fnSetValueOnDTPickerInput(args) { + /* eslint-env browser */ + const textElement = await document.querySelector(args.selector); + textElement.value = args.value; + if (args.onChange) { + textElement.dispatchEvent(new Event('change')); + } + } + })`); await page.evaluate(fn.fnSetValueOnDTPickerInput, args); } diff --git a/src/pages/BO/catalog/products/create/index.ts b/src/pages/BO/catalog/products/create/index.ts index fe0b457a..cfceb0eb 100644 --- a/src/pages/BO/catalog/products/create/index.ts +++ b/src/pages/BO/catalog/products/create/index.ts @@ -6,6 +6,9 @@ const psVersion = testContext.getPSVersion(); /* eslint-disable global-require, @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires */ function requirePage(): BOProductsCreatePageInterface { + if (semver.lt(psVersion, '7.4.0')) { + return require('@versions/1.7.3/pages/BO/catalog/products/create').createProduct; + } if (semver.lt(psVersion, '7.6.0')) { return require('@versions/1.7.5/pages/BO/catalog/products/create').createProduct; } diff --git a/src/pages/BO/catalog/products/index.ts b/src/pages/BO/catalog/products/index.ts index 671bf42b..7f3174a1 100644 --- a/src/pages/BO/catalog/products/index.ts +++ b/src/pages/BO/catalog/products/index.ts @@ -6,6 +6,9 @@ const psVersion = testContext.getPSVersion(); /* eslint-disable global-require, @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires */ function requirePage(): BOProductsPageInterface { + if (semver.lt(psVersion, '7.4.0')) { + return require('@versions/1.7.3/pages/BO/catalog/products').productsPage; + } if (semver.lt(psVersion, '7.6.0')) { return require('@versions/1.7.5/pages/BO/catalog/products').productsPage; } diff --git a/src/versions/1.7.3/pages/BO/catalog/products/create/index.ts b/src/versions/1.7.3/pages/BO/catalog/products/create/index.ts new file mode 100644 index 00000000..ed164b52 --- /dev/null +++ b/src/versions/1.7.3/pages/BO/catalog/products/create/index.ts @@ -0,0 +1,35 @@ +// Import pages +import type {BOProductsCreatePageInterface} from '@interfaces/BO/catalog/products/create'; +import {CreateProduct} from '@versions/1.7.5/pages/BO/catalog/products/create'; +import {type Page} from '@playwright/test'; + +/** + * Bo create product page, contains functions that can be used on the page + * @class + * @extends CreateProduct + */ +class BOCreateProductVersion extends CreateProduct implements BOProductsCreatePageInterface { + /** + * @constructs + * Setting up texts and selectors to use on create products page + */ + constructor() { + super(); + + this.deleteProductButton = '#product_form_delete_btn'; + } + + /** + * Delete product + * @param page {Page} Browser tab + * @returns {Promise} + */ + async deleteProduct(page: Page): Promise { + await this.clickAndWaitForURL(page, this.deleteProductButton); + + return this.getAlertSuccessBlockParagraphContent(page); + } +} + +const createProduct = new BOCreateProductVersion(); +export {createProduct, BOCreateProductVersion as CreateProduct}; diff --git a/src/versions/1.7.3/pages/BO/catalog/products/index.ts b/src/versions/1.7.3/pages/BO/catalog/products/index.ts new file mode 100644 index 00000000..9036a955 --- /dev/null +++ b/src/versions/1.7.3/pages/BO/catalog/products/index.ts @@ -0,0 +1,35 @@ +// Import pages +import type {BOProductsPageInterface} from '@interfaces/BO/catalog/products'; +import {ProductsPage} from '@versions/1.7.5/pages/BO/catalog/products'; +import {type Page} from '@playwright/test'; + +/** + * Bo products page, contains functions that can be used on the page + * @class + * @extends ProductsPage + */ +class BOProductsVersion extends ProductsPage implements BOProductsPageInterface { + /** + * @constructs + * Setting up texts and selectors to use on products page + */ + constructor() { + super(); + + // Products list + this.productsListTableColumnName = (row: number) => `${this.productsListTableRow(row)} td:nth-child(3) a`; + this.productsListTableColumnReference = (row: number) => `${this.productsListTableRow(row)} td:nth-child(4)`; + this.productsListTableColumnCategory = (row: number) => `${this.productsListTableRow(row)} td:nth-child(5)`; + this.productsListTableColumnPriceTExc = (row: number) => `${this.productsListTableRow(row)} td:nth-child(6) a`; + this.productsListTableColumnPriceATI = (row: number) => `${this.productsListTableRow(row)} td:nth-child(7)`; + this.productsListTableColumnStatus = (row: number) => `${this.productsListTableRow(row)} td:nth-child(8)`; + this.productListTableDropDownList = (row: number) => `${this.productsListTableRow(row)} td div.btn-group-action ` + + 'a.dropdown-toggle'; + + // Bulk actions + this.selectAllProductsCheckbox = '#bulk_action_select_all'; + } +} + +const productsPage = new BOProductsVersion(); +export {productsPage, BOProductsVersion as ProductsPage}; \ No newline at end of file diff --git a/src/versions/develop/pages/BO/catalog/products/create/index.ts b/src/versions/develop/pages/BO/catalog/products/create/index.ts index c36b6262..8b80cf59 100644 --- a/src/versions/develop/pages/BO/catalog/products/create/index.ts +++ b/src/versions/develop/pages/BO/catalog/products/create/index.ts @@ -78,7 +78,7 @@ class CreateProduct extends BOBasePage implements BOProductsCreatePageInterface public saveProductButton: string; - private readonly deleteProductButton: string; + protected deleteProductButton: string; private readonly deleteProductFooterModal: string; diff --git a/src/versions/develop/pages/BO/catalog/products/index.ts b/src/versions/develop/pages/BO/catalog/products/index.ts index 56f22491..98d1a2c5 100644 --- a/src/versions/develop/pages/BO/catalog/products/index.ts +++ b/src/versions/develop/pages/BO/catalog/products/index.ts @@ -765,6 +765,7 @@ class ProductsPage extends BOBasePage implements BOProductsPageInterface { // Do nothing } // click on search + await page.mouse.click(100,100); await this.clickAndWaitForLoadState(page, this.filterSearchButton, 'networkidle', 10000); } From 27b54bb4a3c622e4d7ea9005a72d0f8d70e3d589 Mon Sep 17 00:00:00 2001 From: nesrineabdmouleh Date: Thu, 7 Nov 2024 15:05:22 +0100 Subject: [PATCH 2/2] Fix lint errors --- src/pages/BO/BOBasePage.ts | 33 +++++++++---------- src/pages/BO/catalog/products/create/index.ts | 2 +- .../1.7.3/pages/BO/catalog/products/index.ts | 3 +- .../pages/BO/catalog/products/index.ts | 2 +- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/pages/BO/BOBasePage.ts b/src/pages/BO/BOBasePage.ts index 923587b6..79106a0c 100644 --- a/src/pages/BO/BOBasePage.ts +++ b/src/pages/BO/BOBasePage.ts @@ -738,6 +738,7 @@ export default class BOBasePage extends CommonPage implements BOBasePagePageInte */ async goToSubMenu(page: Page, parentSelector: string, linkSelector: string): Promise { const shopVersion = testContext.getPSVersion(); + if (semver.lt(shopVersion, '7.4.0')) { await page.hover(parentSelector); await this.clickAndWaitForURL(page, linkSelector); @@ -1002,14 +1003,13 @@ export default class BOBasePage extends CommonPage implements BOBasePagePageInte const args = {selector: iFrameSelector, vl: value, hasP: hasParagraph}; // eslint-disable-next-line no-eval const fn: { fnSetValueOnTinymceInput: PageFunction<{ selector: string, vl: string, hasP: boolean }, void> } = eval(`({ - async fnSetValueOnTinymceInput(args) { - /* eslint-env browser */ - const iFrameElement = await document.querySelector(args.selector); - const iFrameHtml = iFrameElement.contentDocument.documentElement; - const textElement = await iFrameHtml.querySelector(args.hasP ? 'body p' : 'body'); - textElement.textContent = args.vl; - } - })`); + async fnSetValueOnTinymceInput(args) { + /* eslint-env browser */ + const iFrameElement = await document.querySelector(args.selector); + const iFrameHtml = iFrameElement.contentDocument.documentElement; + const textElement = await iFrameHtml.querySelector(args.hasP ? 'body p' : 'body'); + textElement.textContent = args.vl; + }})`); await page.evaluate(fn.fnSetValueOnTinymceInput, args); } @@ -1035,15 +1035,14 @@ export default class BOBasePage extends CommonPage implements BOBasePagePageInte const args = {selector, value, onChange}; // eslint-disable-next-line no-eval const fn: { fnSetValueOnDTPickerInput: PageFunction<{ selector: string, value: string, onChange: boolean }, void> } = eval(`({ - async fnSetValueOnDTPickerInput(args) { - /* eslint-env browser */ - const textElement = await document.querySelector(args.selector); - textElement.value = args.value; - if (args.onChange) { - textElement.dispatchEvent(new Event('change')); - } - } - })`); + async fnSetValueOnDTPickerInput(args) { + /* eslint-env browser */ + const textElement = await document.querySelector(args.selector); + textElement.value = args.value; + if (args.onChange) { + textElement.dispatchEvent(new Event('change')); + } + }})`); await page.evaluate(fn.fnSetValueOnDTPickerInput, args); } diff --git a/src/pages/BO/catalog/products/create/index.ts b/src/pages/BO/catalog/products/create/index.ts index cfceb0eb..e1fee541 100644 --- a/src/pages/BO/catalog/products/create/index.ts +++ b/src/pages/BO/catalog/products/create/index.ts @@ -8,7 +8,7 @@ const psVersion = testContext.getPSVersion(); function requirePage(): BOProductsCreatePageInterface { if (semver.lt(psVersion, '7.4.0')) { return require('@versions/1.7.3/pages/BO/catalog/products/create').createProduct; - } + } if (semver.lt(psVersion, '7.6.0')) { return require('@versions/1.7.5/pages/BO/catalog/products/create').createProduct; } diff --git a/src/versions/1.7.3/pages/BO/catalog/products/index.ts b/src/versions/1.7.3/pages/BO/catalog/products/index.ts index 9036a955..81affbca 100644 --- a/src/versions/1.7.3/pages/BO/catalog/products/index.ts +++ b/src/versions/1.7.3/pages/BO/catalog/products/index.ts @@ -1,7 +1,6 @@ // Import pages import type {BOProductsPageInterface} from '@interfaces/BO/catalog/products'; import {ProductsPage} from '@versions/1.7.5/pages/BO/catalog/products'; -import {type Page} from '@playwright/test'; /** * Bo products page, contains functions that can be used on the page @@ -32,4 +31,4 @@ class BOProductsVersion extends ProductsPage implements BOProductsPageInterface } const productsPage = new BOProductsVersion(); -export {productsPage, BOProductsVersion as ProductsPage}; \ No newline at end of file +export {productsPage, BOProductsVersion as ProductsPage}; diff --git a/src/versions/develop/pages/BO/catalog/products/index.ts b/src/versions/develop/pages/BO/catalog/products/index.ts index 98d1a2c5..5c4a69e6 100644 --- a/src/versions/develop/pages/BO/catalog/products/index.ts +++ b/src/versions/develop/pages/BO/catalog/products/index.ts @@ -765,7 +765,7 @@ class ProductsPage extends BOBasePage implements BOProductsPageInterface { // Do nothing } // click on search - await page.mouse.click(100,100); + await page.mouse.click(100, 100); await this.clickAndWaitForLoadState(page, this.filterSearchButton, 'networkidle', 10000); }