From 3c1ea796ff3b338a38b1b29ba70b9ed73b5067a1 Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Thu, 2 May 2024 15:32:05 +0200 Subject: [PATCH] `@ops/BO/catalog/product` : Added first commonTest --- src/index.ts | 3 + src/ops/BO/catalog/product.ts | 225 ++++++++++++++++++++++++++++++++++ tsconfig.json | 3 + 3 files changed, 231 insertions(+) create mode 100644 src/ops/BO/catalog/product.ts diff --git a/src/index.ts b/src/index.ts index e1a3e48c..18b06204 100644 --- a/src/index.ts +++ b/src/index.ts @@ -50,6 +50,9 @@ export {default as FakerTaxRule} from '@data/faker/taxRule'; export {default as FakerTitle} from '@data/faker/title'; export {default as FakerZone} from '@data/faker/zone'; +// Export common +export {default as opsBOCatalogProduct} from '@ops/BO/catalog/product' + // Export Pages export * as CommonPage from '@pages/commonPage'; // Export Pages BO diff --git a/src/ops/BO/catalog/product.ts b/src/ops/BO/catalog/product.ts new file mode 100644 index 00000000..02035511 --- /dev/null +++ b/src/ops/BO/catalog/product.ts @@ -0,0 +1,225 @@ +import test, { Page, expect } from '@playwright/test'; +import FakerProduct from '@data/faker/product'; +import boProductsPage from '@pages/BO/catalog/products'; +import boProductsCreatePage from '@pages/BO/catalog/products/create'; +import boDashboardPage from '@pages/BO/dashboard'; +import boLoginPage from '@pages/BO/login'; +import utilsTest from '@utils/test'; + +let numberOfProducts: number; + +export default { + /** + * Function to create standard product + * @param page {Page} + * @param productData {FakerProduct} Data to set to create product + * @param baseContext {string} String to identify the test + */ + async createProduct(page: Page, productData: FakerProduct, baseContext: string = 'commonTests-createProduct'): Promise { + test('should login in BO', async function () { + await utilsTest.addContextItem(test.info(), 'testIdentifier', 'loginBO', baseContext); + + await boLoginPage.goTo(page, global.BO.URL); + await boLoginPage.successLogin(page, global.BO.EMAIL, global.BO.PASSWD); + + const pageTitle = await boDashboardPage.getPageTitle(page); + expect(pageTitle).toContain(boDashboardPage.pageTitle); + }); + + test('should go to \'Catalog > Products\' page', async function () { + await utilsTest.addContextItem(test.info(), 'testIdentifier', 'goToProductsPage', baseContext); + + await boDashboardPage.goToSubMenu(page, boDashboardPage.catalogParentLink, boDashboardPage.productsLink); + await boProductsPage.closeSfToolBar(page); + + const pageTitle = await boProductsPage.getPageTitle(page); + expect(pageTitle).toContain(boProductsPage.pageTitle); + }); + + test('should click on \'New product\' button and check new product modal', async function () { + await utilsTest.addContextItem(test.info(), 'testIdentifier', 'clickOnNewProductButton', baseContext); + + const isModalVisible = await boProductsPage.clickOnNewProductButton(page); + expect(isModalVisible).toBeTruthy(); + }); + + test(`should choose '${productData.type} product' and go to new product page`, async function () { + await utilsTest.addContextItem(test.info(), 'testIdentifier', 'chooseTypeOfProduct', baseContext); + + await boProductsPage.selectProductType(page, productData.type); + await boProductsPage.clickOnAddNewProduct(page); + await boProductsCreatePage.closeSfToolBar(page); + + const pageTitle = await boProductsCreatePage.getPageTitle(page); + expect(pageTitle).toContain(boProductsCreatePage.pageTitle); + }); + + test('should create product', async function () { + await utilsTest.addContextItem(test.info(), 'testIdentifier', 'createStandardProduct', baseContext); + + const createProductMessage = await boProductsCreatePage.setProduct(page, productData); + expect(createProductMessage).toEqual(boProductsCreatePage.successfulUpdateMessage); + }); + + test('should logout', async function () { + await utilsTest.addContextItem(test.info(), 'testIdentifier', 'logout', baseContext); + + await boProductsCreatePage.logoutBO(page); + + const pageTitle = await boLoginPage.getPageTitle(page); + expect(pageTitle).toContain(boLoginPage.pageTitle); + }); + }, + + /** + * Function to delete product + * @param page {Page} + * @param productData {FakerProduct} Data to set to delete product + * @param baseContext {string} String to identify the test + */ + async deleteProduct(page: Page, productData: FakerProduct, baseContext: string = 'commonTests-deleteProduct'): Promise { + test('should login in BO', async function () { + await utilsTest.addContextItem(test.info(), 'testIdentifier', 'loginBO', baseContext); + + await boLoginPage.goTo(page, global.BO.URL); + await boLoginPage.successLogin(page, global.BO.EMAIL, global.BO.PASSWD); + + const pageTitle = await boDashboardPage.getPageTitle(page); + expect(pageTitle).toContain(boDashboardPage.pageTitle); + }); + + test('should go to \'Catalog > Products\' page', async function () { + await utilsTest.addContextItem(test.info(), 'testIdentifier', 'goToProductsPageToDelete', baseContext); + + await boDashboardPage.goToSubMenu(page, boDashboardPage.catalogParentLink, boDashboardPage.productsLink); + + const pageTitle = await boProductsPage.getPageTitle(page); + expect(pageTitle).toContain(boProductsPage.pageTitle); + }); + + test('should reset all filters', async function () { + await utilsTest.addContextItem(test.info(), 'testIdentifier', 'resetFilters', baseContext); + + await boProductsPage.resetFilter(page); + + const numberOfProducts = await boProductsPage.resetAndGetNumberOfLines(page); + expect(numberOfProducts).toBeGreaterThan(0); + }); + + test('should click on delete product button', async function () { + await utilsTest.addContextItem(test.info(), 'testIdentifier', 'clickOnDeleteProduct', baseContext); + + const isModalVisible: boolean = await boProductsPage.clickOnDeleteProductButton(page); + expect(isModalVisible).toBeTruthy(); + }); + + test('should delete product', async function () { + await utilsTest.addContextItem(test.info(), 'testIdentifier', 'deleteProduct', baseContext); + + const textMessage: string = await boProductsPage.clickOnConfirmDialogButton(page); + expect(textMessage).toEqual(boProductsPage.successfulDeleteMessage); + }); + + test('should reset filter', async function () { + await utilsTest.addContextItem(test.info(), 'testIdentifier', 'resetFilter', baseContext); + + const numberOfProductsAfterReset: number = await boProductsPage.resetAndGetNumberOfLines(page); + expect(numberOfProductsAfterReset).toBeGreaterThan(0); + }); + }, + +/** + * Function to bulk delete product + * @param productName {string} Value to set on product name input + * @param baseContext {string} String to identify the test + */ +/* +function bulkDeleteProductsTest(productName: string, baseContext: string = 'commonTests-bulkDeleteProductsTest'): void { + describe('POST-TEST: Bulk delete created products', async () => { + let numberOfProductsAfterFilter: number; + + // before and after functions + before(async function () { + browserContext = await helper.createBrowserContext(this.browser); + page = await helper.newTab(browserContext); + }); + + after(async () => { + await helper.closeBrowserContext(browserContext); + }); + + test('should login in BO', async function () { + await utilsTest.addContextItem(test.info(), 'testIdentifier', 'loginBO', baseContext); + + await boLoginPage.goTo(page, global.BO.URL); + await boLoginPage.successLogin(page, global.BO.EMAIL, global.BO.PASSWD); + + const pageTitle = await boDashboardPage.getPageTitle(page); + expect(pageTitle).toContain(boDashboardPage.pageTitle); + }); + + test('should go to \'Catalog > Products\' page', async function () { + await utilsTest.addContextItem(test.info(), 'testIdentifier', 'goToProductsPageToBulkDelete', baseContext); + + await dashboardPage.goToSubMenu(page, dashboardPage.catalogParentLink, dashboardPage.productsLink); + + const pageTitle = await productsPage.getPageTitle(page); + expect(pageTitle).to.contains(productsPage.pageTitle); + }); + + test('should reset filter and get number of products', async function () { + await utilsTest.addContextItem(test.info(), 'testIdentifier', 'getNumberOfProduct', baseContext); + + numberOfProducts = await productsPage.resetAndGetNumberOfLines(page); + expect(numberOfProducts).to.be.above(0); + }); + + test('should filter list by \'Name\' and check result', async function () { + await utilsTest.addContextItem(test.info(), 'testIdentifier', 'filterListByReference', baseContext); + + await productsPage.filterProducts(page, 'product_name', productName, 'input'); + + numberOfProductsAfterFilter = await productsPage.getNumberOfProductsFromList(page); + + const textColumn = await productsPage.getTextColumn(page, 'product_name', 1); + expect(textColumn).to.contains(productName); + }); + + test('should select the products', async function () { + await utilsTest.addContextItem(test.info(), 'testIdentifier', 'selectProducts', baseContext); + + const isBulkDeleteButtonEnabled = await productsPage.bulkSelectProducts(page); + expect(isBulkDeleteButtonEnabled).to.be.eq(true); + }); + + test('should click on bulk actions button', async function () { + await utilsTest.addContextItem(test.info(), 'testIdentifier', 'clickOnBulkActionsButton', baseContext); + + const textMessage = await productsPage.clickOnBulkActionsProducts(page, 'delete'); + expect(textMessage).to.equal(`Deleting ${numberOfProductsAfterFilter} products`); + }); + + test('should bulk delete products', async function () { + await utilsTest.addContextItem(test.info(), 'testIdentifier', 'bulkDeleteProducts', baseContext); + + const textMessage = await productsPage.bulkActionsProduct(page, 'delete'); + expect(textMessage).to.equal(`Deleting ${numberOfProductsAfterFilter} / ${numberOfProductsAfterFilter} products`); + }); + + test('should close progress modal', async function () { + await utilsTest.addContextItem(test.info(), 'testIdentifier', 'closeDeleteProgressModal', baseContext); + + const isModalVisible = await productsPage.closeBulkActionsProgressModal(page, 'delete'); + expect(isModalVisible).to.be.eq(true); + }); + + test('should reset filter and get number of products', async function () { + await utilsTest.addContextItem(test.info(), 'testIdentifier', 'checkNumberOfProduct', baseContext); + + const numberOfProductAfterBulkActions = await productsPage.resetAndGetNumberOfLines(page); + expect(numberOfProductAfterBulkActions).to.be.equal(numberOfProducts - numberOfProductsAfterFilter); + }); + }); +}*/ + +}; \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index f62269a1..2a06d1b9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -26,6 +26,9 @@ "@interfaces/*": [ "src/interfaces/*" ], + "@ops/*": [ + "src/ops/*" + ], "@pages/*": [ "src/pages/*" ],