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

Catalog FO tests with puppeteer - Sanity tests campaign #15389

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
49 changes: 49 additions & 0 deletions tests/puppeteer/campaigns/sanity/catalogFO/01_filterProducts.js
@@ -0,0 +1,49 @@
// Using chai
const {expect} = require('chai');

// Importing pages
const HomePage = require('../../../pages/FO/home');
const ProductPage = require('../../../pages/FO/product');

let page;
let homePage;
let productPage;
let allProductsNumber = 0;

// creating pages objects in a function
const init = async () => {
page = await global.browser.newPage();
boubkerbribri marked this conversation as resolved.
Show resolved Hide resolved
homePage = await (new HomePage(page));
productPage = await (new ProductPage(page));
};

/*
Open the FO home page
Get the product number
Filter products by a category
Filter products by a subcategory
*/
global.scenario('Filter Products by categories in Home page', () => {
test('should open the shop page', async () => {
await homePage.goTo(global.URL_FO);
await homePage.checkHomePage();
});

test('should check and get the products number', async () => {
await homePage.waitForSelectorAndClick(homePage.allProductLink);
allProductsNumber = await homePage.getNumberOfProducts();
await expect(allProductsNumber).to.be.above(0);
});

test('should filter products by the category "Accessories" and check result', async () => {
await homePage.filterByCategory('6');
const numberOfProducts = await homePage.getNumberOfProducts();
await expect(numberOfProducts).to.be.below(allProductsNumber);
});

test('should filter products by the subcategory "Stationery" and check result', async () => {
await homePage.filterSubCategory('6', '7');
const numberOfProducts = await homePage.getNumberOfProducts();
await expect(numberOfProducts).to.be.below(allProductsNumber);
});
}, init, true);
31 changes: 31 additions & 0 deletions tests/puppeteer/campaigns/sanity/catalogFO/02_checkProduct.js
@@ -0,0 +1,31 @@
// Using chai
const {expect} = require('chai');

// Importing pages
const HomePage = require('../../../pages/FO/home');
const ProductPage = require('../../../pages/FO/product');
const ProductData = require('../../data/FO/product');

let page;
let homePage;
let productPage;

// creating pages objects in a function
const init = async () => {
page = await global.browser.newPage();
homePage = await (new HomePage(page));
productPage = await (new ProductPage(page));
};

/*
Open the FO home page
Check the first product page
*/
global.scenario('Check the Product page', () => {
test('should open the shop page', async () => {
boubkerbribri marked this conversation as resolved.
Show resolved Hide resolved
await homePage.goTo(global.URL_FO);
await homePage.checkHomePage();
});
test('should go to the first product page', () => homePage.goToProductPage('1'));
nesrineabdmouleh marked this conversation as resolved.
Show resolved Hide resolved
test('should check the product page', () => productPage.checkProduct(ProductData.firstProductData));
}, init, true);
33 changes: 32 additions & 1 deletion tests/puppeteer/pages/FO/home.js
Expand Up @@ -9,6 +9,9 @@ module.exports = class Home extends CommonPage {
this.productImg = '#content .products div:nth-child(%NUMBER) article img';
this.userInfoLink = '#_desktop_user_info';
this.contactLink = '#contact-link';
this.allProductLink = '#content a.all-product-link';
nesrineabdmouleh marked this conversation as resolved.
Show resolved Hide resolved
this.totalProducts = '#js-product-list-top .total-products > p';
this.categoryMenu = '#category-%ID > a'
}

/**
Expand All @@ -19,11 +22,39 @@ module.exports = class Home extends CommonPage {
}

/**
* Go the product page
* Go to the product page
* @param id, product id
*/
async goToProductPage(id) {
await this.page.waitForSelector(this.logoHomePage, {visible: true});
await this.waitForSelectorAndClick(this.productImg.replace('%NUMBER', id), 5000);
}

/**
* Get number of products displayed in all products page
* @return integer
*/
async getNumberOfProducts() {
const productNumber = await this.getTextContent(this.totalProducts);
const numberOfProduct = /\d+/g.exec(productNumber.match(/Il y a ([0-9]+)/)).toString();
nesrineabdmouleh marked this conversation as resolved.
Show resolved Hide resolved
nesrineabdmouleh marked this conversation as resolved.
Show resolved Hide resolved
return parseFloat(numberOfProduct);
nesrineabdmouleh marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Filter by category
* @param categoryID, category id from the BO
*/
async filterByCategory(categoryID) {
await this.waitForSelectorAndClick(this.categoryMenu.replace('%ID', categoryID))
nesrineabdmouleh marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Filter by subcategory
* @param categoryID, category id from the BO
* @param subCategoryID, subcategory id from the BO
*/
async filterSubCategory(categoryID, subCategoryID) {
await this.page.hover(this.categoryMenu.replace('%ID', categoryID));
await this.waitForSelectorAndClick(this.categoryMenu.replace('%ID', subCategoryID))
}
};