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

Functional tests - Add new test 'BO > Customers > Transform a Guest to a Customer' #34232

Merged
merged 3 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
// Import utils
import helper from '@utils/helpers';
import testContext from '@utils/testContext';

// Import commonTests
import loginCommon from '@commonTests/BO/loginBO';
import {createOrderByGuestTest} from '@commonTests/FO/order';
import {deleteCustomerTest} from '@commonTests/BO/customers/customer';

// Import BO pages
import dashboardPage from '@pages/BO/dashboard';
import customersPage from '@pages/BO/customers';
import viewCustomerPage from '@pages/BO/customers/view';

// Import data
import PaymentMethods from '@data/demo/paymentMethods';
import Products from '@data/demo/products';
import AddressData from '@data/faker/address';
import CustomerData from '@data/faker/customer';
import OrderData from '@data/faker/order';

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

const baseContext = 'functional_BO_customers_customers_transformGuestToCustomer';

describe('BO - Customers _ Customers : Transform guest to customer account', async () => {
let browserContext: BrowserContext;
let page: Page;
let numberOfCustomers: number;

const customerData: CustomerData = new CustomerData({password: ''});
const addressData: AddressData = new AddressData({country: 'France'});

const orderData: OrderData = new OrderData({
customer: customerData,
products: [
{
product: Products.demo_1,
quantity: 1,
},
],
deliveryAddress: addressData,
paymentMethod: PaymentMethods.wirePayment,
});

// Pre-condition: Create order in FO by guest
createOrderByGuestTest(orderData, 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('Transform a guest to customer account', async () => {
it('should login in BO', async function () {
await loginCommon.loginBO(this, page);
});

it('should go to \'Customers > Customers\' page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToCustomersPage', baseContext);

await dashboardPage.goToSubMenu(
page,
dashboardPage.customersParentLink,
dashboardPage.customersLink,
);
await customersPage.closeSfToolBar(page);

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

it('should reset all filters', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'resetAllFilter', baseContext);

numberOfCustomers = await customersPage.resetAndGetNumberOfLines(page);
expect(numberOfCustomers).to.be.above(1);
});

it('should filter customers group by guest', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'filterCustomer', baseContext);

await customersPage.resetFilter(page);
await customersPage.filterCustomers(page, 'input', 'default_group', 'Guest');

const textEmail = await customersPage.getTextColumnFromTableCustomers(page, 1, 'default_group');
expect(textEmail).to.eq('Guest');
});

it('should go to view customer page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToViewPage', baseContext);

await customersPage.goToViewCustomerPage(page, 1);

const pageTitle = await viewCustomerPage.getPageTitle(page);
expect(pageTitle).to.contains(viewCustomerPage.pageTitle(`${customerData.firstName[0]}. ${customerData.lastName}`));
});

it('should click on transform to customer account', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'clickOnTransferToCustomerAccount', baseContext);

const successMessage = await viewCustomerPage.clickOnTransformToCustomerAccount(page);
expect(successMessage).to.contains(viewCustomerPage.successfulCreationMessage);
});

it('should check the transform to customer account button is not visible', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'isButtonVisible', baseContext);

const isButtonVisible = await viewCustomerPage.isTransformToCustomerAccountButtonVisible(page);
expect(isButtonVisible).to.eq(false);
});

it('should go back to Customers page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goBackToCustomersPage', baseContext);

await dashboardPage.goToSubMenu(page, dashboardPage.customersParentLink, dashboardPage.customersLink);

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

it('should check that the customers table is empty', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkNoRecordFound', baseContext);

const noRecordsFoundText = await customersPage.getTextWhenTableIsEmpty(page);
expect(noRecordsFoundText).to.contains('No records found');
});

it('should reset all filters', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'resetFilter', baseContext);

await customersPage.resetFilter(page);

const numberOfCustomers = await customersPage.resetAndGetNumberOfLines(page);
expect(numberOfCustomers).to.be.at.least(0);
});
});

// Post-condition: Delete customers
deleteCustomerTest(customerData, `${baseContext}_postTest_1`);
});
12 changes: 12 additions & 0 deletions tests/UI/pages/BO/customers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class Customers extends BOBasePage {

private readonly customerGridTitle: string;

private readonly customersEmptyTable: string;

private readonly customersListForm: string;

private readonly customersListTableRow: (row: number) => string;
Expand Down Expand Up @@ -106,6 +108,7 @@ class Customers extends BOBasePage {
this.customerGridPanel = '#customer_grid_panel';
this.customerGridTitle = `${this.customerGridPanel} h3.card-header-title`;
this.customersListForm = '#customer_grid';
this.customersEmptyTable = `${this.customersListForm} tbody div.grid-table-empty`;
this.customersListTableRow = (row: number) => `${this.customersListForm} tbody tr:nth-child(${row})`;
this.customersListTableColumn = (row: number, column: string) => `${this.customersListTableRow(row)} td.column-${column}`;
this.customersListToggleColumn = (row: number, column: string) => `${this.customersListTableColumn(row, column)} .ps-switch`;
Expand Down Expand Up @@ -656,6 +659,15 @@ class Customers extends BOBasePage {
await this.clickAndWaitForURL(page, this.paginationPreviousLink);
return this.getPaginationLabel(page);
}

/**
* Get text when customers table is empty
* @param page {Page} Browser tab
* @returns {Promise<string>}
*/
async getTextWhenTableIsEmpty(page: Page): Promise<string> {
return this.getTextContent(page, this.customersEmptyTable, true);
}
}

export default new Customers();
39 changes: 31 additions & 8 deletions tests/UI/pages/BO/customers/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ class ViewCustomer extends BOBasePage {

public readonly updateSuccessfulMessage: string;

private readonly personnalInformationDiv: string;
private readonly personalInformationDiv: string;

private readonly personnalInformationEditButton: string;
private readonly personalInformationEditButton: string;

private readonly transformCustomerAccountButton: string;

private readonly ordersDiv: string;

Expand Down Expand Up @@ -78,8 +80,9 @@ class ViewCustomer extends BOBasePage {

// Selectors
// Personnel information
this.personnalInformationDiv = '.customer-personal-informations-card';
this.personnalInformationEditButton = `${this.personnalInformationDiv} a.edit-link`;
this.personalInformationDiv = '.customer-personal-informations-card';
this.personalInformationEditButton = `${this.personalInformationDiv} a.edit-link`;
this.transformCustomerAccountButton = '#transfer_guest_account_transfer_guest_account';

// Orders
this.ordersDiv = '.customer-orders-card';
Expand Down Expand Up @@ -187,7 +190,7 @@ class ViewCustomer extends BOBasePage {
* @returns {Promise<string>}
*/
async getPersonalInformationTitle(page: Page | Frame): Promise<string> {
return this.getTextContent(page, this.personnalInformationDiv);
return this.getTextContent(page, this.personalInformationDiv);
}

/**
Expand All @@ -201,7 +204,7 @@ class ViewCustomer extends BOBasePage {

switch (element) {
case 'Personal information':
selector = this.personnalInformationDiv;
selector = this.personalInformationDiv;
break;
case 'Orders':
selector = this.ordersDiv;
Expand Down Expand Up @@ -290,7 +293,7 @@ class ViewCustomer extends BOBasePage {
* @returns {Promise<void>}
*/
async goToEditCustomerPage(page: Page): Promise<void> {
await this.clickAndWaitForURL(page, this.personnalInformationEditButton);
await this.clickAndWaitForURL(page, this.personalInformationEditButton);
}

/**
Expand Down Expand Up @@ -344,7 +347,27 @@ class ViewCustomer extends BOBasePage {
* @returns {Promise<number>}
*/
async getCustomerID(page: Page): Promise<number> {
return this.getNumberFromText(page, this.personnalInformationDiv);
return this.getNumberFromText(page, this.personalInformationDiv);
}

/**
* Click on transform to customer account
* @param page {Page} Browser tab
* @returns {Promise<string>}
*/
async clickOnTransformToCustomerAccount(page: Page): Promise<string> {
await this.clickAndWaitForURL(page, this.transformCustomerAccountButton);

return this.getTextContent(page, `${this.alertSuccessBlock}[role='alert']`);
}

/**
* Is transform to customer account button visible
* @param page {Page} Browser tab
* @returns {Promise<boolean>}
*/
async isTransformToCustomerAccountButtonVisible(page: Page): Promise<boolean> {
return this.elementVisible(page, this.transformCustomerAccountButton, 1000);
}
}

Expand Down