forked from PrestaShop/PrestaShop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
01_filterProducts.js
88 lines (84 loc) · 3.94 KB
/
01_filterProducts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
require('module-alias/register');
// Using chai
const {expect} = require('chai');
const helper = require('@utils/helpers');
const loginCommon = require('@commonTests/loginBO');
// importing pages
const LoginPage = require('@pages/BO/login');
const DashboardPage = require('@pages/BO/dashboard');
const BOBasePage = require('@pages/BO/BObasePage');
const ProductsPage = require('@pages/BO/products');
const {Products} = require('@data/demo/products');
const {Categories} = require('@data/demo/categories');
let browser;
let page;
let numberOfProducts = 0;
// creating pages objects in a function
const init = async function () {
return {
loginPage: new LoginPage(page),
dashboardPage: new DashboardPage(page),
boBasePage: new BOBasePage(page),
productsPage: new ProductsPage(page),
};
};
// Test of filters in products page
describe('Filter in Products Page', async () => {
// before and after functions
before(async function () {
browser = await helper.createBrowser();
page = await helper.newTab(browser);
this.pageObjects = await init();
});
after(async () => {
await helper.closeBrowser(browser);
});
// Steps
loginCommon.loginBO();
it('should go to Products page', async function () {
await this.pageObjects.boBasePage.goToSubMenu(
this.pageObjects.boBasePage.productsParentLink,
this.pageObjects.boBasePage.productsLink,
);
const pageTitle = await this.pageObjects.productsPage.getPageTitle();
await expect(pageTitle).to.contains(this.pageObjects.productsPage.pageTitle);
});
it('should reset all filters and get Number of products in BO', async function () {
if (await this.pageObjects.productsPage.elementVisible(this.pageObjects.productsPage.filterResetButton, 2000)) {
await this.pageObjects.productsPage.resetFilter();
}
await this.pageObjects.productsPage.resetFilterCategory();
numberOfProducts = await this.pageObjects.productsPage.getNumberOfProductsFromList();
await expect(numberOfProducts).to.be.above(0);
});
it('should filter list by Name and check result', async function () {
await this.pageObjects.productsPage.filterProducts('name', Products.demo_14.name);
const numberOfProductsAfterFilter = await this.pageObjects.productsPage.getNumberOfProductsFromList();
await expect(numberOfProductsAfterFilter).to.be.below(numberOfProducts);
});
it('should reset filter and check result', async function () {
await this.pageObjects.productsPage.resetFilter();
const numberOfProductsAfterReset = await this.pageObjects.productsPage.getNumberOfProductsFromList();
await expect(numberOfProductsAfterReset).to.equal(numberOfProducts);
});
it('should filter by Reference and check result', async function () {
await this.pageObjects.productsPage.filterProducts('reference', Products.demo_1.reference);
const numberOfProductsAfterFilter = await this.pageObjects.productsPage.getNumberOfProductsFromList();
await expect(numberOfProductsAfterFilter).to.be.below(numberOfProducts);
});
it('should reset filter and check result', async function () {
await this.pageObjects.productsPage.resetFilter();
const numberOfProductsAfterReset = await this.pageObjects.productsPage.getNumberOfProductsFromList();
await expect(numberOfProductsAfterReset).to.equal(numberOfProducts);
});
it('should filter by Category and check result', async function () {
await this.pageObjects.productsPage.filterProductsByCategory(Categories.men.name);
const numberOfProductsAfterFilter = await this.pageObjects.productsPage.getNumberOfProductsFromList();
await expect(numberOfProductsAfterFilter).to.be.below(numberOfProducts);
});
it('should reset filter Category and check result', async function () {
await this.pageObjects.productsPage.resetFilterCategory();
const numberOfProductsAfterReset = await this.pageObjects.productsPage.getNumberOfProductsFromList();
await expect(numberOfProductsAfterReset).to.equal(numberOfProducts);
});
});