1+ import test , { Page , expect } from '@playwright/test' ;
2+ import FakerProduct from '@data/faker/product' ;
3+ import boProductsPage from '@pages/BO/catalog/products' ;
4+ import boProductsCreatePage from '@pages/BO/catalog/products/create' ;
5+ import boDashboardPage from '@pages/BO/dashboard' ;
6+ import boLoginPage from '@pages/BO/login' ;
7+ import utilsTest from '@utils/test' ;
8+
9+ let numberOfProducts : number ;
10+
11+ export default {
12+ /**
13+ * Function to create standard product
14+ * @param page {Page}
15+ * @param productData {FakerProduct} Data to set to create product
16+ * @param baseContext {string} String to identify the test
17+ */
18+ async createProduct ( page : Page , productData : FakerProduct , baseContext : string = 'commonTests-createProduct' ) : Promise < void > {
19+ test ( 'should login in BO' , async function ( ) {
20+ await utilsTest . addContextItem ( test . info ( ) , 'testIdentifier' , 'loginBO' , baseContext ) ;
21+
22+ await boLoginPage . goTo ( page , global . BO . URL ) ;
23+ await boLoginPage . successLogin ( page , global . BO . EMAIL , global . BO . PASSWD ) ;
24+
25+ const pageTitle = await boDashboardPage . getPageTitle ( page ) ;
26+ expect ( pageTitle ) . toContain ( boDashboardPage . pageTitle ) ;
27+ } ) ;
28+
29+ test ( 'should go to \'Catalog > Products\' page' , async function ( ) {
30+ await utilsTest . addContextItem ( test . info ( ) , 'testIdentifier' , 'goToProductsPage' , baseContext ) ;
31+
32+ await boDashboardPage . goToSubMenu ( page , boDashboardPage . catalogParentLink , boDashboardPage . productsLink ) ;
33+ await boProductsPage . closeSfToolBar ( page ) ;
34+
35+ const pageTitle = await boProductsPage . getPageTitle ( page ) ;
36+ expect ( pageTitle ) . toContain ( boProductsPage . pageTitle ) ;
37+ } ) ;
38+
39+ test ( 'should click on \'New product\' button and check new product modal' , async function ( ) {
40+ await utilsTest . addContextItem ( test . info ( ) , 'testIdentifier' , 'clickOnNewProductButton' , baseContext ) ;
41+
42+ const isModalVisible = await boProductsPage . clickOnNewProductButton ( page ) ;
43+ expect ( isModalVisible ) . toBeTruthy ( ) ;
44+ } ) ;
45+
46+ test ( `should choose '${ productData . type } product' and go to new product page` , async function ( ) {
47+ await utilsTest . addContextItem ( test . info ( ) , 'testIdentifier' , 'chooseTypeOfProduct' , baseContext ) ;
48+
49+ await boProductsPage . selectProductType ( page , productData . type ) ;
50+ await boProductsPage . clickOnAddNewProduct ( page ) ;
51+ await boProductsCreatePage . closeSfToolBar ( page ) ;
52+
53+ const pageTitle = await boProductsCreatePage . getPageTitle ( page ) ;
54+ expect ( pageTitle ) . toContain ( boProductsCreatePage . pageTitle ) ;
55+ } ) ;
56+
57+ test ( 'should create product' , async function ( ) {
58+ await utilsTest . addContextItem ( test . info ( ) , 'testIdentifier' , 'createStandardProduct' , baseContext ) ;
59+
60+ const createProductMessage = await boProductsCreatePage . setProduct ( page , productData ) ;
61+ expect ( createProductMessage ) . toEqual ( boProductsCreatePage . successfulUpdateMessage ) ;
62+ } ) ;
63+
64+ test ( 'should logout' , async function ( ) {
65+ await utilsTest . addContextItem ( test . info ( ) , 'testIdentifier' , 'logout' , baseContext ) ;
66+
67+ await boProductsCreatePage . logoutBO ( page ) ;
68+
69+ const pageTitle = await boLoginPage . getPageTitle ( page ) ;
70+ expect ( pageTitle ) . toContain ( boLoginPage . pageTitle ) ;
71+ } ) ;
72+ } ,
73+
74+ /**
75+ * Function to delete product
76+ * @param page {Page}
77+ * @param productData {FakerProduct} Data to set to delete product
78+ * @param baseContext {string} String to identify the test
79+ */
80+ async deleteProduct ( page : Page , productData : FakerProduct , baseContext : string = 'commonTests-deleteProduct' ) : Promise < void > {
81+ test ( 'should login in BO' , async function ( ) {
82+ await utilsTest . addContextItem ( test . info ( ) , 'testIdentifier' , 'loginBO' , baseContext ) ;
83+
84+ await boLoginPage . goTo ( page , global . BO . URL ) ;
85+ await boLoginPage . successLogin ( page , global . BO . EMAIL , global . BO . PASSWD ) ;
86+
87+ const pageTitle = await boDashboardPage . getPageTitle ( page ) ;
88+ expect ( pageTitle ) . toContain ( boDashboardPage . pageTitle ) ;
89+ } ) ;
90+
91+ test ( 'should go to \'Catalog > Products\' page' , async function ( ) {
92+ await utilsTest . addContextItem ( test . info ( ) , 'testIdentifier' , 'goToProductsPageToDelete' , baseContext ) ;
93+
94+ await boDashboardPage . goToSubMenu ( page , boDashboardPage . catalogParentLink , boDashboardPage . productsLink ) ;
95+
96+ const pageTitle = await boProductsPage . getPageTitle ( page ) ;
97+ expect ( pageTitle ) . toContain ( boProductsPage . pageTitle ) ;
98+ } ) ;
99+
100+ test ( 'should reset all filters' , async function ( ) {
101+ await utilsTest . addContextItem ( test . info ( ) , 'testIdentifier' , 'resetFilters' , baseContext ) ;
102+
103+ await boProductsPage . resetFilter ( page ) ;
104+
105+ const numberOfProducts = await boProductsPage . resetAndGetNumberOfLines ( page ) ;
106+ expect ( numberOfProducts ) . toBeGreaterThan ( 0 ) ;
107+ } ) ;
108+
109+ test ( 'should click on delete product button' , async function ( ) {
110+ await utilsTest . addContextItem ( test . info ( ) , 'testIdentifier' , 'clickOnDeleteProduct' , baseContext ) ;
111+
112+ const isModalVisible : boolean = await boProductsPage . clickOnDeleteProductButton ( page ) ;
113+ expect ( isModalVisible ) . toBeTruthy ( ) ;
114+ } ) ;
115+
116+ test ( 'should delete product' , async function ( ) {
117+ await utilsTest . addContextItem ( test . info ( ) , 'testIdentifier' , 'deleteProduct' , baseContext ) ;
118+
119+ const textMessage : string = await boProductsPage . clickOnConfirmDialogButton ( page ) ;
120+ expect ( textMessage ) . toEqual ( boProductsPage . successfulDeleteMessage ) ;
121+ } ) ;
122+
123+ test ( 'should reset filter' , async function ( ) {
124+ await utilsTest . addContextItem ( test . info ( ) , 'testIdentifier' , 'resetFilter' , baseContext ) ;
125+
126+ const numberOfProductsAfterReset : number = await boProductsPage . resetAndGetNumberOfLines ( page ) ;
127+ expect ( numberOfProductsAfterReset ) . toBeGreaterThan ( 0 ) ;
128+ } ) ;
129+ } ,
130+
131+ /**
132+ * Function to bulk delete product
133+ * @param productName {string} Value to set on product name input
134+ * @param baseContext {string} String to identify the test
135+ */
136+ /*
137+ function bulkDeleteProductsTest(productName: string, baseContext: string = 'commonTests-bulkDeleteProductsTest'): void {
138+ describe('POST-TEST: Bulk delete created products', async () => {
139+ let numberOfProductsAfterFilter: number;
140+
141+ // before and after functions
142+ before(async function () {
143+ browserContext = await helper.createBrowserContext(this.browser);
144+ page = await helper.newTab(browserContext);
145+ });
146+
147+ after(async () => {
148+ await helper.closeBrowserContext(browserContext);
149+ });
150+
151+ test('should login in BO', async function () {
152+ await utilsTest.addContextItem(test.info(), 'testIdentifier', 'loginBO', baseContext);
153+
154+ await boLoginPage.goTo(page, global.BO.URL);
155+ await boLoginPage.successLogin(page, global.BO.EMAIL, global.BO.PASSWD);
156+
157+ const pageTitle = await boDashboardPage.getPageTitle(page);
158+ expect(pageTitle).toContain(boDashboardPage.pageTitle);
159+ });
160+
161+ test('should go to \'Catalog > Products\' page', async function () {
162+ await utilsTest.addContextItem(test.info(), 'testIdentifier', 'goToProductsPageToBulkDelete', baseContext);
163+
164+ await dashboardPage.goToSubMenu(page, dashboardPage.catalogParentLink, dashboardPage.productsLink);
165+
166+ const pageTitle = await productsPage.getPageTitle(page);
167+ expect(pageTitle).to.contains(productsPage.pageTitle);
168+ });
169+
170+ test('should reset filter and get number of products', async function () {
171+ await utilsTest.addContextItem(test.info(), 'testIdentifier', 'getNumberOfProduct', baseContext);
172+
173+ numberOfProducts = await productsPage.resetAndGetNumberOfLines(page);
174+ expect(numberOfProducts).to.be.above(0);
175+ });
176+
177+ test('should filter list by \'Name\' and check result', async function () {
178+ await utilsTest.addContextItem(test.info(), 'testIdentifier', 'filterListByReference', baseContext);
179+
180+ await productsPage.filterProducts(page, 'product_name', productName, 'input');
181+
182+ numberOfProductsAfterFilter = await productsPage.getNumberOfProductsFromList(page);
183+
184+ const textColumn = await productsPage.getTextColumn(page, 'product_name', 1);
185+ expect(textColumn).to.contains(productName);
186+ });
187+
188+ test('should select the products', async function () {
189+ await utilsTest.addContextItem(test.info(), 'testIdentifier', 'selectProducts', baseContext);
190+
191+ const isBulkDeleteButtonEnabled = await productsPage.bulkSelectProducts(page);
192+ expect(isBulkDeleteButtonEnabled).to.be.eq(true);
193+ });
194+
195+ test('should click on bulk actions button', async function () {
196+ await utilsTest.addContextItem(test.info(), 'testIdentifier', 'clickOnBulkActionsButton', baseContext);
197+
198+ const textMessage = await productsPage.clickOnBulkActionsProducts(page, 'delete');
199+ expect(textMessage).to.equal(`Deleting ${numberOfProductsAfterFilter} products`);
200+ });
201+
202+ test('should bulk delete products', async function () {
203+ await utilsTest.addContextItem(test.info(), 'testIdentifier', 'bulkDeleteProducts', baseContext);
204+
205+ const textMessage = await productsPage.bulkActionsProduct(page, 'delete');
206+ expect(textMessage).to.equal(`Deleting ${numberOfProductsAfterFilter} / ${numberOfProductsAfterFilter} products`);
207+ });
208+
209+ test('should close progress modal', async function () {
210+ await utilsTest.addContextItem(test.info(), 'testIdentifier', 'closeDeleteProgressModal', baseContext);
211+
212+ const isModalVisible = await productsPage.closeBulkActionsProgressModal(page, 'delete');
213+ expect(isModalVisible).to.be.eq(true);
214+ });
215+
216+ test('should reset filter and get number of products', async function () {
217+ await utilsTest.addContextItem(test.info(), 'testIdentifier', 'checkNumberOfProduct', baseContext);
218+
219+ const numberOfProductAfterBulkActions = await productsPage.resetAndGetNumberOfLines(page);
220+ expect(numberOfProductAfterBulkActions).to.be.equal(numberOfProducts - numberOfProductsAfterFilter);
221+ });
222+ });
223+ }*/
224+
225+ } ;
0 commit comments