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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functioanl tests - Add new test 'FO > Hummingbird > Change quantity in cart page' #35440

Merged
merged 4 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
Binary file added admin-dev/hummingbird.zip
nesrineabdmouleh marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
// Import utils
import helper from '@utils/helpers';
import testContext from '@utils/testContext';
import files from '@utils/files';

// Import common tests
import {installHummingbird, uninstallHummingbird} from '@commonTests/FO/hummingbird';

// Import FO pages
import cartPage from '@pages/FO/hummingbird/cart';
import homePage from '@pages/FO/hummingbird/home';

import {expect} from 'chai';
import type {BrowserContext, Page} from 'playwright';

const baseContext: string = 'functional_FO_hummingbird_cart_cart_changeQuantity';
/*
Pre-condition:
- Install hummingbird theme
Scenario:
- Go to Fo and add the first product to cart
- Increase/Decrease the product quantity by the touchSpin up/down
- Edit product quantity bu the input (3, -6, +6, 64, 'azerty', 2400, 0)
Post-condition:
- Uninstall hummingbird theme
*/
describe('FO - cart : Change quantity', async () => {
let browserContext: BrowserContext;
let page: Page;

// Pre-condition : Install Hummingbird
installHummingbird(`${baseContext}_preTest`);

before(async function () {
browserContext = await helper.createBrowserContext(this.browser);
page = await helper.newTab(browserContext);
});

after(async () => {
await helper.closeBrowserContext(browserContext);
await files.deleteFile('../../admin-dev/hummingbird.zip');
});

describe('Change quantity', async () => {
it('should go to FO', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToFo', baseContext);

await homePage.goToFo(page);
await homePage.changeLanguage(page, 'en');

const isHomePage = await homePage.isHomePage(page);
expect(isHomePage, 'Fail to open FO home page').to.equal(true);
});

it('should add the first product to cart and proceed to checkout', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'addFirstProductToCart', baseContext);

await homePage.addProductToCartByQuickView(page, 1, 1);
await homePage.proceedToCheckout(page);

const pageTitle = await cartPage.getPageTitle(page);
expect(pageTitle).to.equal(cartPage.pageTitle);
});

it('should increase the product quantity by the touchSpin up to 5', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'increaseQuantity5', baseContext);

const quantity = await cartPage.setProductQuantity(page, 1, 5);
expect(quantity).to.equal(5);

const notificationsNumber = await cartPage.getCartNotificationsNumber(page);
expect(notificationsNumber).to.be.equal(5);
});

it('should decrease the product quantity by the touchSpin down to 2', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'decreaseQuantity2', baseContext);

const quantity = await cartPage.setProductQuantity(page, 1, 2);
expect(quantity).to.equal(2);

const notificationsNumber = await cartPage.getCartNotificationsNumber(page);
expect(notificationsNumber).to.be.equal(2);
});

it('should set the quantity 3 in the input', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'setQuantity3', baseContext);

await cartPage.editProductQuantity(page, 1, 3);

const notificationsNumber = await cartPage.getCartNotificationsNumber(page);
expect(notificationsNumber).to.be.equal(3);
});

it('should set the quantity -6 in the input', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'setQuantity-6', baseContext);

await cartPage.editProductQuantity(page, 1, -6);

const notificationsNumber = await cartPage.getCartNotificationsNumber(page);
expect(notificationsNumber).to.be.equal(3);
});

it('should set the quantity +6 in the input', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'setQuantity+6', baseContext);

await cartPage.editProductQuantity(page, 1, +6);

const notificationsNumber = await cartPage.getCartNotificationsNumber(page);
expect(notificationsNumber).to.be.equal(6);
});

it('should set the quantity 64 in the input', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'setQuantity64', baseContext);

await cartPage.editProductQuantity(page, 1, 64);

const notificationsNumber = await cartPage.getCartNotificationsNumber(page);
expect(notificationsNumber).to.be.equal(64);
});

it('should set \'azerty\' in the input', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'setAZERTY', baseContext);

await cartPage.editProductQuantity(page, 1, 'azerty');

const notificationsNumber = await cartPage.getCartNotificationsNumber(page);
expect(notificationsNumber).to.be.equal(64);
});

it('should set the quantity 2400 in the input', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'setQuantity2400', baseContext);

await cartPage.editProductQuantity(page, 1, 2400);

const notificationsNumber = await cartPage.getCartNotificationsNumber(page);
expect(notificationsNumber).to.be.equal(300);
});

it('should check the error message', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkErrorMessage', baseContext);

const alertText = await cartPage.getNotificationMessage(page);
expect(alertText).to.contains(cartPage.errorNotificationForProductQuantity);
});

it('should set the quantity 3 in the input without validation', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'setQuantityWithoutValidation', baseContext);

await cartPage.setQuantity(page, 1, 3);

const notificationsNumber = await cartPage.getCartNotificationsNumber(page);
expect(notificationsNumber).to.be.equal(300);
});

it('should set the quantity 0 in the input', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'setQuantity', baseContext);

await cartPage.editProductQuantity(page, 1, 0);

const notificationsNumber = await cartPage.getCartNotificationsNumber(page);
expect(notificationsNumber).to.be.equal(300);
});
});

// Post-condition : Uninstall Hummingbird
uninstallHummingbird(`${baseContext}_postTest`);
});
2 changes: 1 addition & 1 deletion tests/UI/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"test:functional:FO:hummingbird": "TEST_PATH='functional/FO/hummingbird/**/*' npm run test:specific",
"test:functional:FO:hummingbird:01-03": "TEST_PATH='functional/FO/hummingbird/0{1,2,3}*/**/*' npm run test:specific",
"test:functional:FO:hummingbird:04-07": "TEST_PATH='functional/FO/hummingbird/0{4,5,6,7}*/**/*' npm run test:specific",
"test:functional:FO:hummingbird:08-12": "TEST_PATH='functional/FO/hummingbird/{08,09,11,12}*/**/*' npm run test:specific",
"test:functional:FO:hummingbird:08-12": "TEST_PATH='functional/FO/hummingbird/{08,09,10,11,12}*/**/*' npm run test:specific",
"// Functional WS": "Scripts to run functional WS tests",
"test:functional:WS": "TEST_PATH='functional/WS/**/*' npm run test:specific",
"// Modules tests": "Scripts to run modules tests",
Expand Down
24 changes: 13 additions & 11 deletions tests/UI/pages/FO/classic/cart/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ class CartPage extends FOBasePage {

protected productQuantity: (number: number) => string;

private readonly productQuantityScrollUpButton: string;
protected productQuantityScrollUpButton: (number: number) => string;

private readonly productQuantityScrollDownButton: string;
protected productQuantityScrollDownButton: (number: number) => string;

protected productSize: (number: number) => string;

Expand All @@ -60,7 +60,7 @@ class CartPage extends FOBasePage {

protected noItemsInYourCartSpan: string;

private readonly alertMessage: string;
protected alertMessage: string;

private readonly subtotalDiscountValueSpan: string;

Expand Down Expand Up @@ -139,8 +139,10 @@ class CartPage extends FOBasePage {
this.productTotalPrice = (number: number) => `${this.productItem(number)} span.product-price`;
this.productQuantity = (number: number) => `${this.productItem(number)} div.input-group `
+ 'input.js-cart-line-product-quantity';
this.productQuantityScrollUpButton = 'button.js-increase-product-quantity.bootstrap-touchspin-up';
this.productQuantityScrollDownButton = 'button.js-decrease-product-quantity.bootstrap-touchspin-down';
this.productQuantityScrollUpButton = (number: number) => `${this.productItem(number)} `
+ 'button.js-increase-product-quantity.bootstrap-touchspin-up';
this.productQuantityScrollDownButton = (number: number) => `${this.productItem(number)} `
+ 'button.js-decrease-product-quantity.bootstrap-touchspin-down';
this.productSize = (number: number) => `${this.productItem(number)} div.product-line-info.size span.value`;
this.productColor = (number: number) => `${this.productItem(number)} div.product-line-info.color span.value`;
this.productImage = (number: number) => `${this.productItem(number)} span.product-image img`;
Expand Down Expand Up @@ -279,26 +281,26 @@ class CartPage extends FOBasePage {
/**
* Set product quantity
* @param page {Page} Browser tab
* @param productID {number} ID of the product
* @param productRow {number} Row of the product
* @param quantity {number} New quantity of the product
* @returns {Promise<number>}
*/
async setProductQuantity(page: Page, productID: number = 1, quantity: number = 1): Promise<number> {
const productQuantity: number = parseInt(await this.getAttributeContent(page, this.productQuantity(productID), 'value'), 10);
async setProductQuantity(page: Page, productRow: number = 1, quantity: number = 1): Promise<number> {
const productQuantity: number = parseInt(await this.getAttributeContent(page, this.productQuantity(productRow), 'value'), 10);

if (productQuantity < quantity) {
for (let i: number = 1; i < quantity; i++) {
await page.locator(this.productQuantityScrollUpButton).click();
await page.locator(this.productQuantityScrollUpButton(productRow)).click();
await page.waitForTimeout(1000);
}
} else {
for (let i: number = productQuantity; i > quantity; i--) {
await page.locator(this.productQuantityScrollDownButton).click();
await page.locator(this.productQuantityScrollDownButton(productRow)).click();
await page.waitForTimeout(1000);
}
}

return parseInt(await this.getAttributeContent(page, this.productQuantity(productID), 'value'), 10);
return parseInt(await this.getAttributeContent(page, this.productQuantity(productRow), 'value'), 10);
}

/**
Expand Down
28 changes: 28 additions & 0 deletions tests/UI/pages/FO/hummingbird/cart/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@ class Cart extends CartPage {
this.productTotalPrice = (number: number) => `${this.productItem(number)} span.product-line__price`;
this.productQuantity = (number: number) => `${this.productItem(number)} div.input-group `
+ 'input.js-cart-line-product-quantity';
this.productQuantityScrollUpButton = (number: number) => `${this.productItem(number)} button.js-increment-button`;
this.productQuantityScrollDownButton = (number: number) => `${this.productItem(number)} button.js-decrement-button`;
this.productImage = (number: number) => `${this.productItem(number)} div.product-line__image img`;
this.productSize = (number: number) => `${this.productItem(number)} div.product-line__info.size span.value`;
this.productColor = (number: number) => `${this.productItem(number)} div.product-line__info.color span.value`;

// Notifications
this.alertMessage = '#js-toast-container div.toast div.toast-body';
}

/**
Expand Down Expand Up @@ -56,6 +61,29 @@ class Cart extends CartPage {
totalPrice: await this.getPriceFromText(page, this.productTotalPrice(row)),
};
}

/**
* Set quantity
* @param page {Page} Browser tab
* @param productID {number} Row of the product
* @param quantity {number} New quantity of the product
* @returns {Promise<void>}
*/
async setQuantity(page: Page, productID: number, quantity: number | string): Promise<void> {
await this.setValue(page, this.productQuantity(productID), quantity);
}

/**
* To edit the product quantity
* @param page {Page} Browser tab
* @param productID {number} Row of the product
* @param quantity {number} New quantity of the product
* @returns {Promise<void>}
*/
async editProductQuantity(page: Page, productID: number, quantity: number | string): Promise<void> {
await this.setValue(page, this.productQuantity(productID), quantity);
await page.locator(this.productQuantityScrollUpButton(productID)).click();
}
}

export default new Cart();