Skip to content

Commit

Permalink
Merge pull request #236 from nesrineabdmouleh/adapt173
Browse files Browse the repository at this point in the history
Migrate 173 selectors to run sanity tests
  • Loading branch information
Progi1984 authored Nov 7, 2024
2 parents 73019b7 + 27b54bb commit be9615e
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 32 deletions.
65 changes: 34 additions & 31 deletions src/pages/BO/BOBasePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -638,7 +638,7 @@ export default class BOBasePage extends CommonPage implements BOBasePagePageInte
* @param page {Page} Browser tab
* @returns {Promise<string>}
*/
async getShopVersion(page:Page):Promise<string> {
async getShopVersion(page: Page): Promise<string> {
return this.getTextContent(page, this.shopVersion);
}

Expand Down Expand Up @@ -737,22 +737,27 @@ export default class BOBasePage extends CommonPage implements BOBasePagePageInte
* @returns {Promise<void>}
*/
async goToSubMenu(page: Page, parentSelector: string, linkSelector: string): Promise<void> {
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}`);
}
}
}

Expand Down Expand Up @@ -998,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);
}

Expand All @@ -1031,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);
}

Expand Down
3 changes: 3 additions & 0 deletions src/pages/BO/catalog/products/create/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions src/pages/BO/catalog/products/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
35 changes: 35 additions & 0 deletions src/versions/1.7.3/pages/BO/catalog/products/create/index.ts
Original file line number Diff line number Diff line change
@@ -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<string>}
*/
async deleteProduct(page: Page): Promise<string> {
await this.clickAndWaitForURL(page, this.deleteProductButton);

return this.getAlertSuccessBlockParagraphContent(page);
}
}

const createProduct = new BOCreateProductVersion();
export {createProduct, BOCreateProductVersion as CreateProduct};
34 changes: 34 additions & 0 deletions src/versions/1.7.3/pages/BO/catalog/products/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Import pages
import type {BOProductsPageInterface} from '@interfaces/BO/catalog/products';
import {ProductsPage} from '@versions/1.7.5/pages/BO/catalog/products';

/**
* 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};
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class CreateProduct extends BOBasePage implements BOProductsCreatePageInterface

public saveProductButton: string;

private readonly deleteProductButton: string;
protected deleteProductButton: string;

private readonly deleteProductFooterModal: string;

Expand Down
1 change: 1 addition & 0 deletions src/versions/develop/pages/BO/catalog/products/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit be9615e

Please sign in to comment.