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 new test 'BO > Shop parameters > Recalculate shipping costs after editing the order ' #34251

Merged
merged 6 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,21 @@ describe('BO - Shop Parameters - Order Settings : Enable/Disable final summary',
expect(isHomePage, 'Home page is not displayed').to.eq(true);
});

it('should check the final summary after checkout', async function () {
await testContext.addContextItem(this, 'testIdentifier', `checkFinalSummary${index}`, baseContext);
it('should add product to cart', async function () {
await testContext.addContextItem(this, 'testIdentifier', `addProductToCart${index}`, baseContext);

// Go to the first product page
await homePage.goToProductPage(page, 1);

// Add the product to the cart
await productPage.addProductToTheCart(page);

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

it('should proceed to checkout and login', async function () {
await testContext.addContextItem(this, 'testIdentifier', `proceedToCheckout${index}`, baseContext);
// Proceed to checkout the shopping cart
await cartPage.clickOnProceedToCheckout(page);

Expand All @@ -103,14 +109,26 @@ describe('BO - Shop Parameters - Order Settings : Enable/Disable final summary',
await checkoutPage.clickOnSignIn(page);
await checkoutPage.customerLogin(page, Customers.johnDoe);
}
});

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 check the final summary after checkout', async function () {
await testContext.addContextItem(this, 'testIdentifier', `checkFinalSummary${index}`, baseContext);

// Check the final summary existence in payment step
const isVisible = await orderConfirmationPage.isFinalSummaryVisible(page);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,32 @@ describe('BO - Shop Parameters - Order Settings : Enable/Disable guest checkout'
expect(isHomePage, 'Home page is not displayed').to.eq(true);
});

it('should verify the guest checkout', async function () {
await testContext.addContextItem(this, 'testIdentifier', `checkGuestCheckout${index}`, baseContext);
it('should add product to cart', async function () {
await testContext.addContextItem(this, 'testIdentifier', `addProductToCart${index}`, baseContext);

// Go to the first product page
await homePage.goToProductPage(page, 1);

// Add the product to the cart
await productPage.addProductToTheCart(page);

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

it('should check active link', async function () {
await testContext.addContextItem(this, 'testIdentifier', `checkIfNoticeVisible${index}`, baseContext);

// Proceed to checkout the shopping cart
await cartPage.clickOnProceedToCheckout(page);

// Check guest checkout
const isNoticeVisible = await checkoutPage.getActiveLinkFromPersonalInformationBlock(page);
expect(isNoticeVisible).to.be.equal(test.args.tabName);
});

it('should verify the guest checkout', async function () {
await testContext.addContextItem(this, 'testIdentifier', `checkGuestCheckout${index}`, baseContext);

const isPasswordRequired = await checkoutPage.isPasswordRequired(page);
expect(isPasswordRequired).to.be.equal(test.args.pwdRequired);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const baseContext: string = 'functional_BO_shopParameters_orderSettings_orderSet

/*
Enable/disable reordering option
Check reordering option in FO (Go to history page and check reodering link)
Check reordering option in FO (Go to history page and check reordering link)
*/
describe('BO - Shop Parameters - Order Settings : Enable/Disable reordering option', async () => {
let browserContext: BrowserContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,22 @@ describe('BO - Shop Parameters - Order Settings : Test minimum purchase total re
expect(isHomePage, 'Home page is not displayed').to.eq(true);
});

it('should verify the minimum purchase total value', async function () {
await testContext.addContextItem(
this,
'testIdentifier',
`checkMinimumPurchaseTotal_${index}`,
baseContext,
);
it('should add product to cart', async function () {
await testContext.addContextItem(this, 'testIdentifier', `addProductToCart_${index}`, baseContext);

// Go to the first product page
await homePage.goToProductPage(page, 1);

// Add the created product to the cart
await productPage.addProductToTheCart(page);

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

it('should verify the minimum purchase total value', async function () {
await testContext.addContextItem(this, 'testIdentifier', `checkMinimumPurchaseTotal_${index}`, baseContext);

// Check proceed to checkout button enable/disable
const isDisabled = await cartPage.isProceedToCheckoutButtonDisabled(page);
expect(isDisabled).to.equal(test.args.disable);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
// Import utils
import helper from '@utils/helpers';
import testContext from '@utils/testContext';

// Import commonTests
import loginCommon from '@commonTests/BO/loginBO';
import {createOrderByCustomerTest} from '@commonTests/FO/order';

// Import BO pages
import dashboardPage from '@pages/BO/dashboard';
import orderSettingsPage from '@pages/BO/shopParameters/orderSettings';
import ordersPage from '@pages/BO/orders';
import orderPageTabListBlock from '@pages/BO/orders/view/tabListBlock';

// Import data
import Customers from '@data/demo/customers';
import OrderData from '@data/faker/order';
import Products from '@data/demo/products';
import PaymentMethods from '@data/demo/paymentMethods';
import OrderShippingData from '@data/faker/orderShipping';
import Carriers from '@data/demo/carriers';

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

const baseContext: string = 'functional_BO_shopParameters_orderSettings_orderSettings_general_recalculateShippingCosts';

describe('BO - Shop Parameters - Order Settings : Recalculate shipping costs after editing the order', async () => {
let browserContext: BrowserContext;
let page: Page;

const orderByCustomerData: OrderData = new OrderData({
customer: Customers.johnDoe,
products: [
{
product: Products.demo_1,
quantity: 1,
},
],
paymentMethod: PaymentMethods.wirePayment,
});

const shippingDetailsData: OrderShippingData = new OrderShippingData({
trackingNumber: '0523698',
carrier: Carriers.myCarrier.name,
carrierID: Carriers.myCarrier.id,
});

const editShippingDetailsData: OrderShippingData = new OrderShippingData({
trackingNumber: '0523698',
carrier: Carriers.default.name,
carrierID: Carriers.default.id,
});

// Pre-condition: Create order in FO
createOrderByCustomerTest(orderByCustomerData, baseContext);

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

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

describe('Set recalculate shipping costs after editing the order', async () => {
it('should login in BO', async function () {
await loginCommon.loginBO(this, page);
});

const tests = [
{
args: {
action: 'enable',
toEnable: true,
carrierData: shippingDetailsData,
cost: '€8.40',
},
},
{
args: {
action: 'disable',
toEnable: false,
carrierData: editShippingDetailsData,
cost: '€8.40',
},
},
];

tests.forEach((test, index: number) => {
it('should go to \'Shop Parameters > Order Settings\' page', async function () {
await testContext.addContextItem(this, 'testIdentifier', `goToOrderSettingsPage_${index}`, baseContext);

await dashboardPage.goToSubMenu(
page,
dashboardPage.shopParametersParentLink,
dashboardPage.orderSettingsLink,
);
await orderSettingsPage.closeSfToolBar(page);

const pageTitle = await orderSettingsPage.getPageTitle(page);
expect(pageTitle).to.contains(orderSettingsPage.pageTitle);
});

it(`should ${test.args.action} final summary`, async function () {
await testContext.addContextItem(this, 'testIdentifier', `${test.args.action}FinalSummary`, baseContext);

const result = await orderSettingsPage.recalculateShippingCostAfterEditingOrder(page, test.args.toEnable);
expect(result).to.contains(orderSettingsPage.successfulUpdateMessage);
});

it('should go to \'Orders > Orders\' page', async function () {
await testContext.addContextItem(this, 'testIdentifier', `goToOrdersPage_${index}`, baseContext);

await dashboardPage.goToSubMenu(
page,
dashboardPage.ordersParentLink,
dashboardPage.ordersLink,
);

const pageTitle = await ordersPage.getPageTitle(page);
expect(pageTitle).to.contains(ordersPage.pageTitle);
});

it('should view the order', async function () {
await testContext.addContextItem(this, 'testIdentifier', `viewOrderPage_${index}`, baseContext);

await ordersPage.goToOrder(page, 1);

const pageTitle = await orderPageTabListBlock.getPageTitle(page);
expect(pageTitle).to.contains(orderPageTabListBlock.pageTitle);
});

it('should click on \'Carriers\' tab', async function () {
await testContext.addContextItem(this, 'testIdentifier', `displayCarriersTab_${index}`, baseContext);

const isTabOpened = await orderPageTabListBlock.goToCarriersTab(page);
expect(isTabOpened).to.eq(true);
});

it('should click on \'Edit\' link and check the modal', async function () {
await testContext.addContextItem(this, 'testIdentifier', `clickOnEditLink_${index}`, baseContext);

const isModalVisible = await orderPageTabListBlock.clickOnEditLink(page);
expect(isModalVisible, 'Edit shipping modal is not visible!').to.eq(true);
});

it('should update the carrier and add a tracking number', async function () {
await testContext.addContextItem(this, 'testIdentifier', `updateTrackingNumber_${index}`, baseContext);

const textResult = await orderPageTabListBlock.setShippingDetails(page, test.args.carrierData!);
expect(textResult).to.equal(orderPageTabListBlock.successfulUpdateMessage);
});

it('should check the updated carrier details', async function () {
await testContext.addContextItem(this, 'testIdentifier', `checkUpdatedCarrierDetails_${index}`, baseContext);

await orderPageTabListBlock.goToCarriersTab(page);

const result = await orderPageTabListBlock.getCarrierDetails(page);
await Promise.all([
expect(result.carrier).to.equal(test.args.carrierData.carrier),
expect(result.shippingCost).to.equal(test.args.cost),
]);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,33 @@ describe('BO - Shop Parameters - Order Settings : Enable/Disable terms of servic
expect(result).to.contains(orderSettingsPage.successfulUpdateMessage);
});

it('should check terms of service checkbox', async function () {
await testContext.addContextItem(this, 'testIdentifier', `checkTermsOfService${index}`, baseContext);
it('should view my shop', async function () {
await testContext.addContextItem(this, 'testIdentifier', `viewMyShop_${index}`, baseContext);

// Click on view my shop
page = await orderSettingsPage.viewMyShop(page);
// Change FO language
await homePage.changeLanguage(page, 'en');

const isHomePage = await homePage.isHomePage(page);
expect(isHomePage, 'Home page is not displayed').to.eq(true);
});

it('should add product to cart', async function () {
await testContext.addContextItem(this, 'testIdentifier', `addProductToCart${index}`, baseContext);

// Go to the first product page
await homePage.goToProductPage(page, 1);
// Add the product to the cart
await productPage.addProductToTheCart(page);
// Proceed to checkout the shopping cart

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

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

await cartPage.clickOnProceedToCheckout(page);

// Checkout the order
Expand All @@ -125,10 +140,18 @@ describe('BO - Shop Parameters - Order Settings : Enable/Disable terms of servic
// 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 check terms of service checkbox', async function () {
await testContext.addContextItem(this, 'testIdentifier', `checkTermsOfService${index}`, baseContext);

// Check terms of service checkbox existence
const isVisible = await checkoutPage.isConditionToApproveCheckboxVisible(page);
Expand Down
17 changes: 17 additions & 0 deletions tests/UI/pages/BO/shopParameters/orderSettings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class OrderSettings extends BOBasePage {

private readonly minimumPurchaseRequiredValue: string;

private readonly recalculateShippingCostAfterEditOrder: (toggle: number) => string;

private readonly enableTermsOfServiceToggleInput: (toggle: number) => string;

private readonly pageForTermsAndConditionsSelect: string;
Expand Down Expand Up @@ -59,6 +61,7 @@ class OrderSettings extends BOBasePage {
this.enableGuestCheckoutToggleInput = (toggle: number) => `#general_enable_guest_checkout_${toggle}`;
this.disableReorderingToggleInput = (toggle: number) => `#general_disable_reordering_option_${toggle}`;
this.minimumPurchaseRequiredValue = '#general_purchase_minimum_value';
this.recalculateShippingCostAfterEditOrder = (toggle: number) => `#general_recalculate_shipping_cost_${toggle}`;
this.enableTermsOfServiceToggleInput = (toggle: number) => `#general_enable_tos_${toggle}`;
this.pageForTermsAndConditionsSelect = '#general_tos_cms_id';
this.saveGeneralFormButton = `${this.generalForm} #form-general-save-button`;
Expand Down Expand Up @@ -131,6 +134,20 @@ class OrderSettings extends BOBasePage {
return this.getAlertSuccessBlockParagraphContent(page);
}

/**
* Recalculate shipping cost after editing order
* @param page {Page} Browser tab
* @param toEnable {boolean} True if we need to enable recalculate shipping cost
* @returns {Promise<string>}
*/
async recalculateShippingCostAfterEditingOrder(page: Page, toEnable: boolean): Promise<string> {
await this.setChecked(page, this.recalculateShippingCostAfterEditOrder(toEnable ? 1 : 0));
await page.click(this.saveGeneralFormButton);
nesrineabdmouleh marked this conversation as resolved.
Show resolved Hide resolved
await this.elementNotVisible(page, this.recalculateShippingCostAfterEditOrder(!toEnable ? 1 : 0), 2000);

return this.getAlertSuccessBlockParagraphContent(page);
}

/**
* Set terms of service
* @param page {Page} Browser tab
Expand Down
Loading