Skip to content

Commit

Permalink
Functional Tests : Hummingbird : FO - Checkout - Payment - Choose a p…
Browse files Browse the repository at this point in the history
…ayment method
  • Loading branch information
Progi1984 committed Feb 2, 2024
1 parent 06853a4 commit 5b35728
Show file tree
Hide file tree
Showing 9 changed files with 252 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
// Import utils
import helper from '@utils/helpers';
import testContext from '@utils/testContext';
import mailHelper from '@utils/mailHelper';

// Import common tests
import {resetSmtpConfigTest, setupSmtpConfigTest} from '@commonTests/BO/advancedParameters/smtp';
import {installHummingbird, uninstallHummingbird} from '@commonTests/FO/hummingbird';

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

// Import data
import Customers from '@data/demo/customers';
import PaymentMethods from '@data/demo/paymentMethods';
import PaymentMethodData from '@data/faker/paymentMethod';

import {expect} from 'chai';
import type {BrowserContext, Page} from 'playwright';
import MailDevEmail from '@data/types/maildevEmail';
import MailDev from 'maildev';

const baseContext: string = 'functional_FO_hummingbird_checkout_payment_choosePaymentMethod';

describe('FO - Checkout - Payment : Choose a payment method', async () => {
let browserContext: BrowserContext;
let page: Page;
let allEmails: MailDevEmail[];
let numberOfEmails: number;
let mailListener: MailDev;

// Pre-Condition : Setup config SMTP
setupSmtpConfigTest(`${baseContext}_preTest_0`);

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

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

mailListener = mailHelper.createMailListener();
mailHelper.startListener(mailListener);

// get all emails
// @ts-ignore
mailListener.getAllEmail((err: Error, emails: MailDevEmail[]) => {
allEmails = emails;
});
});

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

mailHelper.stopListener(mailListener);
});

describe('Choose a payment method', async () => {
[
PaymentMethods.wirePayment,
PaymentMethods.checkPayment,
PaymentMethods.cashOnDelivery,
].forEach((test: PaymentMethodData, index: number) => {
it('should go to FO', async function () {
await testContext.addContextItem(this, 'testIdentifier', `goToFo${index}`, 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 add the first product to cart', async function () {
await testContext.addContextItem(this, 'testIdentifier', `addProductToCart${index}`, baseContext);

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

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

it('should proceed to checkout and go to checkout page', async function () {
await testContext.addContextItem(this, 'testIdentifier', `proceedToCheckout${index}`, baseContext);

await cartPage.clickOnProceedToCheckout(page);

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

if (index === 0) {
it('should signin', async function () {
await testContext.addContextItem(this, 'testIdentifier', `signin${index}`, baseContext);

await checkoutPage.clickOnSignIn(page);

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

it('should go to delivery step', async function () {
await testContext.addContextItem(this, 'testIdentifier', `goToDeliveryStep${index}`, baseContext);

// Address step - Go to delivery step
const isStepAddressComplete = await checkoutPage.goToDeliveryStep(page);
expect(isStepAddressComplete, 'Step Address is not complete').to.eq(true);
});

it('should go to payment step', async function () {
await testContext.addContextItem(this, 'testIdentifier', `goToPaymentStep${index}`, baseContext);

// Delivery step - Go to payment step
const isStepDeliveryComplete = await checkoutPage.goToPaymentStep(page);
expect(isStepDeliveryComplete, 'Step Address is not complete').to.eq(true);
});

it('should choose payment method and confirm the order', async function () {
await testContext.addContextItem(this, 'testIdentifier', `confirmOrder${index}`, baseContext);

// Payment step - Choose payment step
await checkoutPage.choosePaymentAndOrder(page, test.moduleName);

// Check the confirmation message
const cardTitle = await orderConfirmationPage.getOrderConfirmationCardTitle(page);
expect(cardTitle).to.contains(orderConfirmationPage.orderConfirmationCardTitle);
});

it(`should check the payment method is ${test.displayName}`, async function () {
await testContext.addContextItem(this, 'testIdentifier', `checkPaymentMethod${index}`, baseContext);

const paymentMethod = await orderConfirmationPage.getPaymentMethod(page);
expect(paymentMethod).to.be.equal(test.displayName);
});

it('should check if order and payment confirmation mails are in mailbox', async function () {
await testContext.addContextItem(this, 'testIdentifier', `checkPaymentMail${index}`, baseContext);

numberOfEmails = allEmails.length;
expect(allEmails[numberOfEmails - 1].subject).to.equal(`[${global.INSTALL.SHOP_NAME}] Order confirmation`);

if (index === 0) {
expect(allEmails[numberOfEmails - 2].subject).to.equal(`[${global.INSTALL.SHOP_NAME}] Awaiting bank wire payment`);
} else if (index === 1) {
expect(allEmails[numberOfEmails - 2].subject).to.equal(`[${global.INSTALL.SHOP_NAME}] Awaiting check payment`);
}
});
});
});

// Post-condition : Reset SMTP config
resetSmtpConfigTest(`${baseContext}_postTest_0`);

// Post-condition : Uninstall Hummingbird
uninstallHummingbird(`${baseContext}_postTest_1`);
});
2 changes: 1 addition & 1 deletion tests/UI/pages/FO/classic/cart/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class CartPage extends FOBasePage {

private readonly alertWarning: string;

private readonly proceedToCheckoutButton: string;
protected proceedToCheckoutButton: string;

private readonly disabledProceedToCheckoutButton: string;

Expand Down
24 changes: 14 additions & 10 deletions tests/UI/pages/FO/classic/checkout/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ import {ProductDetailsBasic} from '@data/types/product';
* @class
* @extends FOBasePage
*/
class Checkout extends FOBasePage {
class CheckoutPage extends FOBasePage {
public readonly deleteAddressSuccessMessage: string;

private readonly successAlert: string;

private readonly checkoutPageBody: string;

protected stepFormSuccess: string;

public readonly messageIfYouSignOut: string;

public readonly authenticationErrorMessage: string;
Expand Down Expand Up @@ -77,7 +79,7 @@ class Checkout extends FOBasePage {

private readonly checkoutPromoCodeAddButton: string;

public readonly personalInformationStepForm: string;
public personalInformationStepForm: string;

private readonly forgetPasswordLink: string;

Expand Down Expand Up @@ -109,7 +111,7 @@ class Checkout extends FOBasePage {

private readonly checkoutGuestContinueButton: string;

private readonly signInHyperLink: string;
protected signInHyperLink: string;

private readonly checkoutSummary: string;

Expand All @@ -125,7 +127,7 @@ class Checkout extends FOBasePage {

private readonly passwordInput: string;

private readonly personalInformationContinueButton: string;
protected personalInformationContinueButton: string;

private readonly logoutMessage: string;

Expand All @@ -137,7 +139,7 @@ class Checkout extends FOBasePage {

private readonly loginErrorMessage: string;

private readonly addressStepSection: string;
protected addressStepSection: string;

private readonly addressStepContent: string;

Expand Down Expand Up @@ -177,7 +179,7 @@ class Checkout extends FOBasePage {

private readonly invoiceAddressSection: string;

private readonly deliveryStepSection: string;
protected deliveryStepSection: string;

private readonly deliveryStepEditButton: string;

Expand Down Expand Up @@ -243,8 +245,8 @@ class Checkout extends FOBasePage {
* @constructs
* Setting up texts and selectors to use on checkout page
*/
constructor() {
super();
constructor(theme: string = 'classic') {
super(theme);
this.cartRuleAlertMessageText = 'You cannot use this voucher with this carrier';
this.deleteAddressSuccessMessage = 'Address successfully deleted.';
this.noPaymentNeededText = 'No payment needed for this order';
Expand All @@ -254,6 +256,7 @@ class Checkout extends FOBasePage {
// Selectors
this.successAlert = '#notifications article.alert-success';
this.checkoutPageBody = 'body#checkout';
this.stepFormSuccess = '.-complete';

// Personal information form
this.personalInformationStepForm = '#checkout-personal-information-step';
Expand Down Expand Up @@ -405,7 +408,7 @@ class Checkout extends FOBasePage {
* @returns {Promise<boolean>}
*/
async isStepCompleted(page: Page, stepSelector: string): Promise<boolean> {
return this.elementVisible(page, `${stepSelector}.-complete`, 1000);
return this.elementVisible(page, `${stepSelector}${this.stepFormSuccess}`, 1000);
}

/**
Expand Down Expand Up @@ -1241,4 +1244,5 @@ class Checkout extends FOBasePage {
}
}

export default new Checkout();
const checkoutPage = new CheckoutPage();
export {checkoutPage, CheckoutPage};
17 changes: 9 additions & 8 deletions tests/UI/pages/FO/classic/checkout/orderConfirmation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import type {Page} from 'playwright';
* @class
* @extends FOBasePage
*/
class OrderConfirmation extends FOBasePage {
class OrderConfirmationPage extends FOBasePage {
public readonly pageTitle: string;

public readonly orderConfirmationCardTitle: string;

private readonly orderConfirmationCardSection: string;
protected orderConfirmationCardSection: string;

private readonly orderConfirmationCardTitleH3: string;
protected orderConfirmationCardTitleH3: string;

private readonly orderSummaryContent: string;

Expand All @@ -27,16 +27,16 @@ class OrderConfirmation extends FOBasePage {

private readonly giftWrappingRow: string;

private readonly orderDetailsTable: string;
protected orderDetailsTable: string;

private readonly paymentMethodRow: string;
protected paymentMethodRow: string;

/**
* @constructs
* Setting up texts and selectors to use on order confirmation page
*/
constructor() {
super();
constructor(theme: string = 'classic') {
super(theme);

this.pageTitle = 'Order confirmation';
this.orderConfirmationCardTitle = 'Your order is confirmed';
Expand Down Expand Up @@ -115,4 +115,5 @@ class OrderConfirmation extends FOBasePage {
}
}

export default new OrderConfirmation();
const orderConfirmationPage = new OrderConfirmationPage();
export {orderConfirmationPage, OrderConfirmationPage};
4 changes: 2 additions & 2 deletions tests/UI/pages/FO/classic/home/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class HomePage extends FOBasePage {

private readonly blockCartLabel: string;

private readonly blockCartModalDiv: string;
protected readonly blockCartModalDiv: string;

private readonly blockCartModalCloseButton: string;

Expand All @@ -131,7 +131,7 @@ class HomePage extends FOBasePage {

private readonly cartModalProductTaxInclBlock: string;

private readonly cartModalCheckoutLink: string;
protected cartModalCheckoutLink: string;

private readonly continueShoppingButton: string;

Expand Down
2 changes: 2 additions & 0 deletions tests/UI/pages/FO/hummingbird/cart/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class Cart extends CartPage {
*/
constructor() {
super('hummingbird');

this.proceedToCheckoutButton = '#wrapper div.cart-summary div.checkout a.btn';
}
}

Expand Down
35 changes: 35 additions & 0 deletions tests/UI/pages/FO/hummingbird/checkout/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Import FO pages
import {CheckoutPage} from '@pages/FO/classic/checkout';

/**
* Cart page, contains functions that can be used on the page
* @class
* @extends FOBasePage
*/
class Checkout extends CheckoutPage {
/**
* @constructs
*/
constructor() {
super('hummingbird');

// Selectors
this.stepFormSuccess = '.checkout__steps--success';

// Personal information form
this.personalInformationStepForm = 'li[data-step="checkout-personal-information-step"]';

// Sign in selectors
this.signInHyperLink = '#checkout-personal-information-step div.step__content '
+ '#contact-tab[data-bs-target="#checkout-login-form"]';
this.personalInformationContinueButton = '#login-form button[data-link-action="sign-in"]';

// Addresses step selectors
this.addressStepSection = 'li[data-step="checkout-addresses-step"]';

// Shipping method selectors
this.deliveryStepSection = 'li[data-step="checkout-delivery-step"]';
}
}

export default new Checkout();

0 comments on commit 5b35728

Please sign in to comment.