Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functional tests - add test filter stocks by status #16931

Merged
merged 3 commits into from Dec 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,108 @@
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/catalog/products');
const AddProductPage = require('@pages/BO/catalog/products/add');
const StocksPage = require('@pages/BO/catalog/stocks');
const ProductFaker = require('@data/faker/product');

let browser;
let page;
let numberOfProducts = 0;
const productData = new ProductFaker({type: 'Standard product', productHasCombinations: false});

// 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),
addProductPage: new AddProductPage(page),
stocksPage: new StocksPage(page),
};
};
/*
Create new disabled product
Filter stocks page by status and check existence of product
Delete product
*/
describe('Filter stocks by status', 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.catalogParentLink,
this.pageObjects.boBasePage.productsLink,
);
await this.pageObjects.boBasePage.closeSfToolBar();
const pageTitle = await this.pageObjects.productsPage.getPageTitle();
await expect(pageTitle).to.contains(this.pageObjects.productsPage.pageTitle);
});

it('should reset all filters', async function () {
await this.pageObjects.productsPage.resetFilterCategory();
numberOfProducts = await this.pageObjects.productsPage.resetAndGetNumberOfLines();
await expect(numberOfProducts).to.be.above(0);
});

describe('Create new product', async () => {
it('should create Product', async function () {
await this.pageObjects.productsPage.goToAddProductPage();
const createProductMessage = await this.pageObjects.addProductPage.createEditProduct(productData, false);
await expect(createProductMessage).to.equal(this.pageObjects.addProductPage.settingUpdatedMessage);
});
});

describe('Check the disabled product in stocks page', async () => {
it('should go to stocks page', async function () {
await this.pageObjects.addProductPage.goToSubMenu(
this.pageObjects.addProductPage.catalogParentLink,
this.pageObjects.addProductPage.stocksLink,
);
const pageTitle = await this.pageObjects.stocksPage.getPageTitle();
await expect(pageTitle).to.contains(this.pageObjects.stocksPage.pageTitle);
});

it('should filter by status \'disabled\' and check the existence of the created product', async function () {
await this.pageObjects.stocksPage.filterByStatus('disabled');
const textColumn = await this.pageObjects.stocksPage.getTextColumnFromTableStocks(1, 'name');
await expect(textColumn).to.contains(productData.name);
});
});

describe('Delete product', async () => {
it('should go to products page', async function () {
await this.pageObjects.stocksPage.goToSubMenu(
this.pageObjects.stocksPage.catalogParentLink,
this.pageObjects.stocksPage.productsLink,
);
const pageTitle = await this.pageObjects.productsPage.getPageTitle();
await expect(pageTitle).to.contains(this.pageObjects.productsPage.pageTitle);
});

it('should delete product', async function () {
const testResult = await this.pageObjects.productsPage.deleteProduct(productData);
await expect(testResult).to.equal(this.pageObjects.productsPage.productDeletedSuccessfulMessage);
const numberOfProductsAfterDelete = await this.pageObjects.productsPage.resetAndGetNumberOfLines();
await expect(numberOfProductsAfterDelete).to.equal(numberOfProducts);
});
});
});
12 changes: 7 additions & 5 deletions tests/puppeteer/pages/BO/BObasePage.js
Expand Up @@ -123,13 +123,15 @@ module.exports = class BOBasePage extends CommonPage {
* @returns {Promise<void>}
*/
async goToSubMenu(parentSelector, linkSelector) {
if (await this.elementVisible(linkSelector)) {
await this.page.click(linkSelector);
if (!(await this.elementNotVisible(`${parentSelector}.open`, 1000))) {
await this.clickAndWaitForNavigation(linkSelector);
} else {
// open the block
await this.page.click(parentSelector);
await this.page.waitForSelector(`${parentSelector}.open`, {visible: true});
await this.page.click(linkSelector);
await Promise.all([
this.page.click(parentSelector),
this.page.waitForSelector(`${parentSelector}.open`, {visible: true}),
]);
await this.clickAndWaitForNavigation(linkSelector);
}
await this.page.waitForSelector(`${linkSelector}.-active`, {visible: true});
}
Expand Down
32 changes: 32 additions & 0 deletions tests/puppeteer/pages/BO/catalog/stocks/index.js
Expand Up @@ -37,6 +37,13 @@ module.exports = class Stocks extends BOBasePage {

// loader
this.productListLoading = `${this.productRow.replace('%ROW', 1)} td:nth-child(1) div.ps-loader`;

// Filters containers
this.filtersContainerDiv = '#filters-container';
this.advancedFiltersButton = `${this.filtersContainerDiv} button[data-target='#filters']`;
this.filterStatusEnabledLabel = '#enable + label';
this.filterStatusDisabledLabel = '#disable + label';
this.filterStatusAllLabel = '#all + label';
}

/*
Expand Down Expand Up @@ -161,4 +168,29 @@ module.exports = class Stocks extends BOBasePage {
await this.page.click(this.alertBoxButtonClose);
return textContent;
}

/**
* Filter stocks by product's status
* @param status
* @return {Promise<void>}
*/
async filterByStatus(status) {
await Promise.all([
this.page.click(this.advancedFiltersButton),
this.page.waitForSelector(`${this.advancedFiltersButton}[aria-expanded='true']`, {visible: true}),
]);
switch (status) {
case 'enabled':
await this.page.click(this.filterStatusEnabledLabel);
break;
case 'disabled':
await this.page.click(this.filterStatusDisabledLabel);
break;
case 'all':
await this.page.click(this.filterStatusAllLabel);
break;
default:
throw Error(`${status} was not found as an option`);
}
}
};