Skip to content

Commit

Permalink
Functional Tests : Hummingbird : FO - Checkout - Shipping method - Se…
Browse files Browse the repository at this point in the history
…lect a carrier
  • Loading branch information
Progi1984 committed Feb 9, 2024
1 parent 5bf9bf4 commit d359b4f
Show file tree
Hide file tree
Showing 3 changed files with 252 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
// Import utils
import helper from '@utils/helpers';
import testContext from '@utils/testContext';

// Import common tests
import {deleteCustomerTest} from '@commonTests/BO/customers/customer';
import createAccountTest from '@commonTests/FO/hummingbird/account';
import {installHummingbird, uninstallHummingbird} from '@commonTests/FO/hummingbird';

// Import FO pages
import cartPage from '@pages/FO/hummingbird/cart';
import checkoutPage from '@pages/FO/hummingbird/checkout';
import homePage from '@pages/FO/hummingbird/home';
import productPage from '@pages/FO/hummingbird/product';

// Import data
import Carriers from '@data/demo/carriers';
import AddressData from '@data/faker/address';
import CustomerData from '@data/faker/customer';
import Products from '@data/demo/products';

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

const baseContext: string = 'functional_FO_hummingbird_checkout_shippingMethods_selectCarrier';

/*
Pre-condition:
- Create new customer account in FO
Scenario:
- Add a product to cart and checkout
- Create an address in Europe and check the carriers
- Edit the address to US and check the carriers
Post-condition:
- Delete customer account
*/

describe('FO - Checkout - Shipping methods : Select carrier', async () => {
let browserContext: BrowserContext;
let page: Page;
const customerData: CustomerData = new CustomerData();
const addressData: AddressData = new AddressData({
email: customerData.email,
country: 'France',
});
const addressDataInUnitedStates: AddressData = new AddressData({
email: customerData.email,
country: 'United States',
state: 'Alabama',
});

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

// Pre-condition: Create new account on FO
createAccountTest(customerData, `${baseContext}_preTest_1`);

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

after(async () => {
await helper.closeBrowserContext(browserContext);
});

describe('Add a product to the cart and checkout', 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.eq(true);
});

it('should go to first product page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToProductPage', baseContext);

await homePage.goToProductPage(page, 1);

const pageTitle = await productPage.getPageTitle(page);
expect(pageTitle).to.contains(Products.demo_1.name);
});

it('should add product to cart and go to cart page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'addProductToCart', baseContext);

await productPage.addProductToTheCart(page);

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

it('should validate shopping cart and go to checkout page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToCheckoutPage', baseContext);

await cartPage.clickOnProceedToCheckout(page);

const isCheckoutPage = await checkoutPage.isCheckoutPage(page);
expect(isCheckoutPage).to.eq(true);
});

it('should sign in by created customer', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'signInFO', baseContext);

await checkoutPage.clickOnSignIn(page);

const isCustomerConnected = await checkoutPage.customerLogin(page, customerData);
expect(isCustomerConnected, 'Customer is not connected!').to.eq(true);
});
});

describe('Select carrier in Europe address', async () => {
it('should create address in Europe then continue to shipping methods', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'createAddress', baseContext);

const isStepAddressComplete = await checkoutPage.setAddress(page, addressData);
expect(isStepAddressComplete, 'Step Address is not complete').to.eq(true);
});

it('should check the carriers list', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkCarriersList', baseContext);

const carriers = await checkoutPage.getAllCarriersNames(page);
expect(carriers).to.deep.equal([Carriers.default.name, Carriers.myCarrier.name]);
});

it('should check the first carrier data', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkFirstCarrierData', baseContext);

const carrierData = await checkoutPage.getCarrierData(page, 1);
await Promise.all([
expect(carrierData.name).to.equal(Carriers.default.name),
expect(carrierData.delay).to.equal(Carriers.default.delay),
expect(carrierData.priceText).to.equal('Free'),
]);
});

it('should check the second carrier data', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkSecondCarrierData', baseContext);

const carrierData = await checkoutPage.getCarrierData(page, 2);
await Promise.all([
expect(carrierData.name).to.equal(Carriers.myCarrier.name),
expect(carrierData.delay).to.equal(Carriers.myCarrier.delay),
expect(carrierData.priceText).to.equal(`€${Carriers.myCarrier.priceTTC.toFixed(2)} tax incl.`),
]);
});

it('should select the first carrier and check the shipping price', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkShippingPrice1', baseContext);

await checkoutPage.chooseShippingMethod(page, Carriers.default.id);

const shippingCost = await checkoutPage.getShippingCost(page);
expect(shippingCost).to.equal('Free');
});

it('should select the second carrier and check the shipping price', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkShippingPrice2', baseContext);

await checkoutPage.chooseShippingMethod(page, Carriers.myCarrier.id);

const shippingCost = await checkoutPage.getShippingCost(page);
expect(shippingCost).to.equal(`€${Carriers.myCarrier.priceTTC.toFixed(2)}`);
});
});

describe('Select carrier in US address', async () => {
it('should click on edit addresses step', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'clickEditAddressStep', baseContext);

await checkoutPage.clickOnEditAddressesStep(page);

const addressesNumber = await checkoutPage.getNumberOfAddresses(page);
expect(addressesNumber, 'The addresses number is not equal to 1!').to.equal(1);
});

it('should edit the created address', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'editCreatedAddress', baseContext);

await checkoutPage.clickOnEditAddress(page);
await checkoutPage.setAddress(page, addressDataInUnitedStates);

const isStepCompleted = await checkoutPage.clickOnContinueButtonFromAddressStep(page);
expect(isStepCompleted).to.eq(true);
});

it('should check the carriers list', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkCarriersList2', baseContext);

const carriers = await checkoutPage.getAllCarriersNames(page);
expect(carriers).to.deep.equal([Carriers.myCarrier.name]);
});

it('should check the carrier data', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkFirstCarrierData2', baseContext);

const carrierData = await checkoutPage.getCarrierData(page, 2);
await Promise.all([
expect(carrierData.name).to.equal(Carriers.myCarrier.name),
expect(carrierData.delay).to.equal(Carriers.myCarrier.delay),
expect(carrierData.priceText).to.equal(`€${Carriers.myCarrier.price.toFixed(2)}`),
]);
});

it('should check the shipping price', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkShippingPrice3', baseContext);

const shippingCost = await checkoutPage.getShippingCost(page);
expect(shippingCost).to.equal(`€${Carriers.myCarrier.price.toFixed(2)}`);
});
});

// Post-condition: Delete the created customer account
deleteCustomerTest(customerData, `${baseContext}_postTest_0`);

// Post-condition : Uninstall Hummingbird
uninstallHummingbird(`${baseContext}_postTest_1`);
});
28 changes: 14 additions & 14 deletions tests/UI/pages/FO/classic/checkout/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CheckoutPage extends FOBasePage {

private readonly paymentConfirmationButton: string;

private readonly shippingValueSpan: string;
protected shippingValueSpan: string;

private readonly blockPromoDiv: string;

Expand Down Expand Up @@ -155,19 +155,19 @@ class CheckoutPage extends FOBasePage {

private readonly addressStepCityInput: string;

private readonly addressStepCountrySelect: string;
protected addressStepCountrySelect: string;

private readonly addressStepPhoneInput: string;

private readonly stateInput: string;
protected stateInput: string;

private readonly addressStepUseSameAddressCheckbox: string;

private readonly addressStepContinueButton: string;

private readonly addressStepSubmitButton: string;

private readonly addressStepEditButton: string;
protected addressStepEditButton: string;

private readonly addAddressButton: string;

Expand All @@ -185,29 +185,29 @@ class CheckoutPage extends FOBasePage {

private readonly deliveryStepCarriersList: string;

private readonly deliveryOptions: string;
protected deliveryOptions: string;

private readonly deliveryOptionsRadioButton: string;

private readonly deliveryOptionLabel: (id: number) => string;
protected deliveryOptionLabel: (id: number) => string;

private readonly deliveryOptionNameSpan: (id: number) => string;

private readonly deliveryOptionAllNamesSpan: string;
protected deliveryOptionAllNamesSpan: string;

private readonly deliveryOptionAllPricesSpan: string;

private readonly deliveryMessage: string;

private readonly deliveryStepContinueButton: string;

private readonly deliveryOption: (carrierID: number) => string;
protected deliveryOption: (carrierID: number) => string;

private readonly deliveryStepCarrierName: (carrierID: number) => string;
protected deliveryStepCarrierName: (carrierID: number) => string;

private readonly deliveryStepCarrierDelay: (carrierID: number) => string;
protected deliveryStepCarrierDelay: (carrierID: number) => string;

private readonly deliveryStepCarrierPrice: (carrierID: number) => string;
protected deliveryStepCarrierPrice: (carrierID: number) => string;

private readonly deliveryAddressBlock: string;

Expand All @@ -217,7 +217,7 @@ class CheckoutPage extends FOBasePage {

private readonly invoiceAddressPosition: (position: number) => string;

private readonly deliveryAddressEditButton: (addressID: number) => string;
protected deliveryAddressEditButton: (addressID: number) => string;

private readonly deliveryAddressDeleteButton: (addressID: number) => string;

Expand Down Expand Up @@ -909,7 +909,7 @@ class CheckoutPage extends FOBasePage {
* Get order message
* @param page {Page} Browser tab
*/
getOrderMessage(page: Page): Promise<string> {
async getOrderMessage(page: Page): Promise<string> {
return this.getTextContent(page, this.deliveryMessage);
}

Expand Down Expand Up @@ -1025,7 +1025,7 @@ class CheckoutPage extends FOBasePage {
* @param page {Page} Browser tab
* @returns {Promise<boolean>}
*/
isPaymentConfirmationButtonVisibleAndEnabled(page: Page): Promise<boolean> {
async isPaymentConfirmationButtonVisibleAndEnabled(page: Page): Promise<boolean> {
// small side effect note, the selector is the one that checks for disabled
return this.elementVisible(page, this.paymentConfirmationButton, 1000);
}
Expand Down
16 changes: 16 additions & 0 deletions tests/UI/pages/FO/hummingbird/checkout/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,26 @@ class Checkout extends CheckoutPage {

// Addresses step selectors
this.addressStepSection = 'li[data-step="checkout-addresses-step"]';
this.addressStepCountrySelect = 'select[name="id_country"]';
this.stateInput = 'select[name="id_state"]';
this.addressStepEditButton = `${this.addressStepSection} button`;

// Shipping method selectors
this.deliveryStepSection = 'li[data-step="checkout-delivery-step"]';
this.deliveryOptionAllNamesSpan = '#js-delivery .delivery-options__container span.carrier-name';
this.deliveryAddressPosition = (position) => `#delivery-addresses div:nth-child(${position}) article`;
this.deliveryAddressEditButton = (addressID: number) => `#id_address_delivery-address-${addressID} a.address__edit`;
this.deliveryOptions = '#js-delivery .delivery-options__container';
this.deliveryOptionLabel = (id: number) => `input#delivery_option_${id}`;
this.deliveryOption = (carrierID: number) => `${this.deliveryOptions} label[for="delivery_option_${carrierID}"]`;
this.deliveryStepCarrierName = (carrierID: number) => `${this.deliveryOption(carrierID)} span.carrier-name`;
this.deliveryStepCarrierDelay = (carrierID: number) => `${this.deliveryOption(carrierID)} div.row`
+ ' > span.delivery-option__center';
this.deliveryStepCarrierPrice = (carrierID: number) => `${this.deliveryOption(carrierID)} div.row`
+ ' > span.delivery-option__right';

// Checkout summary selectors
this.shippingValueSpan = '#cart-subtotal-shipping span.cart-summary__value';
}
}

Expand Down

0 comments on commit d359b4f

Please sign in to comment.