From 0c1b8c6acce3799a6268a93f9201d560885a9ab4 Mon Sep 17 00:00:00 2001 From: Shay Date: Tue, 21 Jan 2025 11:28:31 +0100 Subject: [PATCH] Reworked password change test to not interfere with other tests --- tests/base/account.spec.ts | 39 +++++++++++++++++++++++++++++------- tests/base/config/slugs.json | 3 ++- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/tests/base/account.spec.ts b/tests/base/account.spec.ts index a1ecf4b..ffeada7 100644 --- a/tests/base/account.spec.ts +++ b/tests/base/account.spec.ts @@ -1,5 +1,7 @@ import {test, expect} from '@playwright/test'; +import {MainMenuPage} from './fixtures/mainmenu.page'; import {LoginPage} from './fixtures/login.page'; +import {RegisterPage} from './fixtures/register.page'; import {AccountPage} from './fixtures/account.page'; import {NewsletterSubscriptionPage} from './fixtures/newsletter.page'; @@ -46,24 +48,47 @@ test.describe('Account information actions', {annotation: {type: 'Account Dashbo * @then I should see a notification that my password has been updated * @and I should be able to login with my new credentials. */ + test('I can change my password',{ tag: '@account-credentials', }, async ({page, browserName}) => { - //TODO: Remove the skip when all issues are fixed. - test.skip('I can change my password',{ tag: '@account-credentials', }, async ({page}) => { + // Create instances and set variables + const mainMenu = new MainMenuPage(page); + const registerPage = new RegisterPage(page); const accountPage = new AccountPage(page); - let changedPasswordValue = process.env.MAGENTO_EXISTING_ACCOUNT_CHANGED_PASSWORD; + const loginPage = new LoginPage(page); + + const browserEngine = browserName?.toUpperCase() || "UNKNOWN"; + let randomNumberforEmail = Math.floor(Math.random() * 101); + let emailPasswordUpdatevalue = `passwordupdate-${randomNumberforEmail}-${browserEngine}@example.com`; let passwordInputValue = process.env.MAGENTO_EXISTING_ACCOUNT_PASSWORD; + let changedPasswordValue = process.env.MAGENTO_EXISTING_ACCOUNT_CHANGED_PASSWORD; + + // Log out of current account + if(await page.getByRole('link', { name: selectors.mainMenu.myAccountLogoutItem }).isVisible()){ + await mainMenu.logout(); + } + // Create account if(!changedPasswordValue || !passwordInputValue) { throw new Error("Changed password or original password in your .env file is not defined or could not be read."); } - // Navigate to Account Information, confirm by checking heading above sidebar - const sidebarAccountInfoLink = page.getByRole('link', { name: 'Account Information' }); - sidebarAccountInfoLink.click(); - await expect(page.getByRole('heading', { name: 'Account Information' }).locator('span')).toBeVisible(); + await registerPage.createNewAccount(inputvalues.accountCreation.firstNameValue, inputvalues.accountCreation.lastNameValue, emailPasswordUpdatevalue, passwordInputValue); + // Update password + await page.goto(slugs.account.changePasswordSlug); + await page.waitForLoadState(); await accountPage.updatePassword(passwordInputValue, changedPasswordValue); + // If login with changePasswordValue is possible, then password change was succesful. + await loginPage.login(emailPasswordUpdatevalue, changedPasswordValue); + + // Logout again, login with original account + await mainMenu.logout(); + let emailInputValue = process.env[`MAGENTO_EXISTING_ACCOUNT_EMAIL_${browserEngine}`]; + if(!emailInputValue) { + throw new Error("MAGENTO_EXISTING_ACCOUNT_EMAIL_${browserEngine} and/or MAGENTO_EXISTING_ACCOUNT_PASSWORD have not defined in the .env file, or the account hasn't been created yet."); + } + await loginPage.login(emailInputValue, passwordInputValue); }); }); diff --git a/tests/base/config/slugs.json b/tests/base/config/slugs.json index 20673df..d6293a5 100644 --- a/tests/base/config/slugs.json +++ b/tests/base/config/slugs.json @@ -5,7 +5,8 @@ "createAccountSlug": "/customer/account/create", "addressBookSlug": "/customer/address", "addressIndexSlug": "/customer/address/index", - "addressNewSlug": "customer/address/new" + "addressNewSlug": "customer/address/new", + "changePasswordSlug": "/customer/account/edit/changepass/1/" }, "productpage": { "simpleProductSlug": "/push-it-messenger-bag.html",