Skip to content

Commit

Permalink
Merge pull request PrestaShop#35308 from nesrineabdmouleh/TEST-4986
Browse files Browse the repository at this point in the history
Functional tests - Add new test 'FO > Hummingbird > Subscribe to newsletter'
  • Loading branch information
nesrineabdmouleh authored Feb 12, 2024
2 parents 8485d1a + cc3f286 commit 040d786
Show file tree
Hide file tree
Showing 3 changed files with 241 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
// Import utils
import helper from '@utils/helpers';
import testContext from '@utils/testContext';
import files from '@utils/files';

// Import commonTests
import loginCommon from '@commonTests/BO/loginBO';
import {installHummingbird, uninstallHummingbird} from '@commonTests/FO/hummingbird';

// Import pages
// Import BO pages
import dashboardPage from '@pages/BO/dashboard';
import {moduleManager as moduleManagerPage} from '@pages/BO/modules/moduleManager';
import {moduleConfigurationPage} from '@pages/BO/modules/moduleConfiguration';
import psEmailSubscriptionPage from '@pages/BO/modules/psEmailSubscription';
// Import FO pages
import homePage from '@pages/FO/hummingbird/home';
import loginPage from '@pages/FO/hummingbird/login';
import myAccountPage from '@pages/FO/hummingbird/myAccount';
import accountIdentityPage from '@pages/FO/hummingbird/myAccount/identity';

// Import data
import Customers from '@data/demo/customers';
import ModuleData from '@data/faker/module';

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

// context
const baseContext: string = 'functional_FO_hummingbird_newsletter_subscribeNewsletter';

/*
Pre-condition:
- Install hummingbird
Scenario:
- Go to the FO homepage
- Fill the subscribe newsletter field and subscribe
- Go to BO in newsletter module
- Check if correctly subscribed
- Go back to the FO homepage
- Try to subscribe again with the same email
- Go to back to BO and delete subscription
Post-condition:
- Uninstall hummingbird
*/
describe('FO - Newsletter : Subscribe to Newsletter', async () => {
let browserContext: BrowserContext;
let page: Page;

const moduleInformation: ModuleData = new ModuleData({
tag: 'ps_emailsubscription',
name: 'Newsletter subscription',
});

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

// before and after functions
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('Go to FO and try to subscribe with already used email', async () => {
it('should open the shop page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'openFoShop', baseContext);

await homePage.goTo(page, global.FO.URL);

const result = await homePage.isHomePage(page);
expect(result).to.eq(true);
});

it('should subscribe to newsletter with already used email', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'subscribeWithAlreadyUsedEmail', baseContext);

const newsletterSubscribeAlertMessage = await homePage.subscribeToNewsletter(page, Customers.johnDoe.email);
expect(newsletterSubscribeAlertMessage).to.contains(homePage.alreadyUsedEmailMessage);
});
});

describe('Go to FO customer account to unsubscribe newsletter', async () => {
it('should go to login page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToFOLoginPage', baseContext);

await homePage.goToLoginPage(page);

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

it('Should sign in FO', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'signInFo', baseContext);

await loginPage.customerLogin(page, Customers.johnDoe);

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

it('should go to account information page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToAccountInformationPage', baseContext);

await homePage.goToMyAccountPage(page);
await myAccountPage.goToInformationPage(page);

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

it('should unsubscribe from newsletter', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'unsubscribeFromNewsLetter', baseContext);

const unsubscribeAlertText = await accountIdentityPage.unsubscribeNewsletter(page, Customers.johnDoe.password);
expect(unsubscribeAlertText).to.contains(accountIdentityPage.successfulUpdateMessage);
});
});

describe('Go to BO to check if correctly unsubscribed', async () => {
it('should login in BO', async function () {
await loginCommon.loginBO(this, page);
});

it('should go to module manager page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToModuleManagerPage', baseContext);

await dashboardPage.goToSubMenu(
page,
dashboardPage.modulesParentLink,
dashboardPage.moduleManagerLink,
);
await moduleManagerPage.closeSfToolBar(page);

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

it(`should search for module ${moduleInformation.name}`, async function () {
await testContext.addContextItem(this, 'testIdentifier', 'searchForModule', baseContext);

const isModuleVisible = await moduleManagerPage.searchModule(page, moduleInformation);
expect(isModuleVisible).to.eq(true);
});

it('should go to newsletter subscription module configuration page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToNewsletterModuleConfigPage', baseContext);

await moduleManagerPage.searchModule(page, moduleInformation);
await moduleManagerPage.goToConfigurationPage(page, moduleInformation.tag);

const moduleConfigurationPageSubtitle = await moduleConfigurationPage.getPageSubtitle(page);
expect(moduleConfigurationPageSubtitle).to.contains(moduleInformation.name);
});

it('should check if user is unsubscribed from newsletter', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkThatEmailIsNotInTable', baseContext);

const subscribedUserList = await psEmailSubscriptionPage.getListOfNewsletterRegistrationEmails(page);
expect(subscribedUserList).to.not.contains(Customers.johnDoe.email);
});

it('should logout from BO', async function () {
await loginCommon.logoutBO(this, page);
});
});

describe('Go to FO to subscribe to the newsletter', async () => {
it('should open the shop page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToFOToSubscribeToNewsletter', baseContext);

await homePage.goTo(page, global.FO.URL);

const result = await homePage.isHomePage(page);
expect(result).to.eq(true);
});

it('should subscribe to newsletter', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'subscribeToNewsletter', baseContext);

const newsletterSubscribeAlertMessage = await homePage.subscribeToNewsletter(page, Customers.johnDoe.email);
expect(newsletterSubscribeAlertMessage).to.contains(homePage.successSubscriptionMessage);
});
});

describe('Go to BO to check if correctly subscribed', async () => {
it('should login in BO', async function () {
await loginCommon.loginBO(this, page);
});

it('should go to module manager page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToBOToCheckIfSubscribed', baseContext);

await dashboardPage.goToSubMenu(
page,
dashboardPage.modulesParentLink,
dashboardPage.moduleManagerLink,
);
await moduleManagerPage.closeSfToolBar(page);

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

it('should go to newsletter subscription module configuration page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goBackToNewsletterModuleConfig', baseContext);

await moduleManagerPage.searchModule(page, moduleInformation);
await moduleManagerPage.goToConfigurationPage(page, moduleInformation.tag);

const moduleConfigurationPageSubtitle = await moduleConfigurationPage.getPageSubtitle(page);
expect(moduleConfigurationPageSubtitle).to.contains(moduleInformation.name);
});

it('should check if previous customer subscription is visible in table', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkIfSubscriptionIsInTable', baseContext);

const subscribedUserList = await psEmailSubscriptionPage.getListOfNewsletterRegistrationEmails(page);
expect(subscribedUserList).to.contains(Customers.johnDoe.email);
});

it('should logout from BO', async function () {
await loginCommon.logoutBO(this, page);
});
});

// Post-condition : Uninstall Hummingbird
uninstallHummingbird(`${baseContext}_postTest`);
});
6 changes: 3 additions & 3 deletions tests/UI/pages/FO/classic/home/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ class HomePage extends FOBasePage {

private readonly customTextBlock: string;

private readonly newsletterFormField: string;
protected newsletterFormField: string;

private readonly newsletterSubmitButton: string;
protected newsletterSubmitButton: string;

private readonly subscriptionAlertMessage: string;
protected subscriptionAlertMessage: string;

private readonly quickViewModalDiv: string;

Expand Down
5 changes: 5 additions & 0 deletions tests/UI/pages/FO/hummingbird/home/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class Home extends HomePage {
// Wishlist modal
this.wishlistModal = '.wishlist-add-to .wishlist-modal.show';
this.wishlistModalTitle = '.wishlist-modal.show p.modal-title';

// Newsletter form
this.newsletterFormField = '#footer div.email-subscription__content__right input[name="email"]';
this.newsletterSubmitButton = '.email-subscription__content__inputs [name="submitNewsletter"][value="Subscribe"]';
this.subscriptionAlertMessage = '#footer div.email-subscription__content__infos p.alert';
}

/**
Expand Down

0 comments on commit 040d786

Please sign in to comment.