From 6c3766c0f016d3b010a7967317deae08d2711b6b Mon Sep 17 00:00:00 2001 From: Arjen Miedema Date: Mon, 28 Oct 2024 11:53:15 +0100 Subject: [PATCH] Update codebase to use 2 spaces in *.ts and *.json To stick with best practices for JavaScript related languages both the TypeScript and JSON files are set to use two spaces instead of four. This is also defined in the `.editorconfig` file so all systems will handle this the same. --- .editorconfig | 12 + tests/base/account.spec.ts | 457 +++++++++--------- tests/base/config/test-toggles.example.json | 27 +- tests/base/config/test-toggles.json | 33 +- tests/base/contact.spec.ts | 37 +- tests/base/fixtures/before/slugs.json | 54 +-- tests/base/fixtures/before/websites.json | 4 +- .../fixtures/during/input-values/account.json | 36 +- .../fixtures/during/input-values/contact.json | 12 +- .../fixtures/during/input-values/search.json | 4 +- .../fixtures/during/selectors/account.json | 54 +-- .../fixtures/during/selectors/contact.json | 12 +- .../fixtures/during/selectors/example.json | 4 +- .../fixtures/during/selectors/global.json | 6 +- .../fixtures/during/selectors/minicart.json | 16 +- .../during/selectors/product-page.json | 6 +- .../base/fixtures/verify/expects/account.json | 50 +- .../base/fixtures/verify/expects/contact.json | 4 +- .../base/fixtures/verify/expects/example.json | 6 +- .../base/fixtures/verify/expects/global.json | 4 +- .../fixtures/verify/expects/minicart.json | 6 +- .../fixtures/verify/expects/product-page.json | 2 +- tests/base/minicart.spec.ts | 85 ++-- tests/base/pages.spec.ts | 62 +-- tests/base/utils/Account.ts | 32 +- tests/base/utils/Browser.ts | 67 +-- tests/base/utils/Cart.ts | 31 +- tests/base/utils/Checkout.ts | 12 +- tests/base/utils/Contact.ts | 22 +- tests/base/utils/PageTester.ts | 90 ++-- 30 files changed, 627 insertions(+), 620 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..38a54dd --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[*.{ts,json}] +indent_size = 2 \ No newline at end of file diff --git a/tests/base/account.spec.ts b/tests/base/account.spec.ts index 834f072..6cfca99 100644 --- a/tests/base/account.spec.ts +++ b/tests/base/account.spec.ts @@ -1,6 +1,6 @@ -import { test, expect, selectors } from '@playwright/test'; -import { PageTester } from './utils/PageTester'; -import { Account } from './utils/Account'; +import {test, expect, selectors} from '@playwright/test'; +import {PageTester} from './utils/PageTester'; +import {Account} from './utils/Account'; import dotenv from 'dotenv'; import toggle from './config/test-toggles.json'; @@ -11,251 +11,250 @@ import accountValue from './fixtures/during/input-values/account.json'; import accountExpected from './fixtures/verify/expects/account.json'; test.describe('Test user flow', () => { + const existingAccountEmail = process.env.MAGENTO_EXISTING_ACCOUNT_EMAIL; + const existingAccountPassword = process.env.MAGENTO_EXISTING_ACCOUNT_PASSWORD; + const existingAccountChangedPassword = process.env.MAGENTO_EXISTING_ACCOUNT_CHANGED_PASSWORD; - const existingAccountEmail = process.env.MAGENTO_EXISTING_ACCOUNT_EMAIL; - const existingAccountPassword = process.env.MAGENTO_EXISTING_ACCOUNT_PASSWORD; - const existingAccountChangedPassword = process.env.MAGENTO_EXISTING_ACCOUNT_CHANGED_PASSWORD; - - if(toggle.account.testAccountCreation) { - test('Create an account', async ({ page }) => { - const randomNumber = Math.floor(Math.random() * 10000000); - const emailHandle = accountValue.newAccountEmailHandle; - const emailHost = accountValue.newAccountEmailHost; - const uniqueEmail = `${emailHandle}${randomNumber}@${emailHost}`; - - await page.goto(slugs.accountCreationSlug); - - await page.fill(accountSelector.registrationFirstNameSelector, accountValue.newAccountFirstName); - await page.fill(accountSelector.registrationLastNameSelector, accountValue.newAccountLastName); - await page.fill(accountSelector.registrationEmailAddressSelector, uniqueEmail); - await page.fill(accountSelector.registrationPasswordSelector, existingAccountPassword); - await page.fill(accountSelector.registrationConfirmPasswordSelector, existingAccountPassword); - - await page.click(accountSelector.registrationCreateAccountButtonSelector); - - const uniqueSuccessfulAccountCreationNotificationText = accountExpected.uniqueSuccessfulAccountCreationNotificationText; - await expect(page.locator(`text=${uniqueSuccessfulAccountCreationNotificationText}`)).toBeVisible(); - - console.log(`Account created with credentials: email address "${uniqueEmail}" and password "${newAccountPassword}"`); - }); - } - - if(toggle.account.testAccountLogin) { - test('Login with an account', async ({ page }) => { - const account = new Account(page); - await account.login(existingAccountEmail, existingAccountPassword); - - const accountPageTester = new PageTester(page, page.url()); - await accountPageTester.testPage(); - await expect(page.locator(`text=${existingAccountEmail}`)).toBeVisible(); - }); - } - - test('Add new address on account', async ({ page }) => { - const account = new Account(page); - await account.login(existingAccountEmail, existingAccountPassword); - - await page.goto(slugs.accountNewAddressSlug); - await page.fill(accountSelector.registrationFirstNameSelector, accountValue.newAccountFirstName); - await page.fill(accountSelector.registrationLastNameSelector, accountValue.newAccountLastName); - await page.fill(accountSelector.accountTelephoneSelector, accountValue.newAddressTelephoneNumber); - await page.fill(accountSelector.accountStreetAddressSelector, accountValue.newAddressStreetAddress); - await page.fill(accountSelector.accountZipSelector, accountValue.newAddressZipCode); - await page.fill(accountSelector.accountCitySelector, accountValue.newAddressCityName); - await page.selectOption(accountSelector.accountProvinceSelector, { value: accountValue.newAddressProvinceValue }); - - await page.click(accountSelector.accountAddressSaveButtonSelector); - - await expect(page.locator(`text=${accountExpected.accountAddressChangedNotificationText}`)).toBeVisible(); - - const accountPageTester = new PageTester(page, page.url()); - await accountPageTester.testPage(); - }); + if (toggle.account.testAccountCreation) { + test('Create an account', async ({page}) => { + const randomNumber = Math.floor(Math.random() * 10000000); + const emailHandle = accountValue.newAccountEmailHandle; + const emailHost = accountValue.newAccountEmailHost; + const uniqueEmail = `${emailHandle}${randomNumber}@${emailHost}`; + + await page.goto(slugs.accountCreationSlug); - test('Edit address on account', async ({ page }) => { - const account = new Account(page); - await account.login(existingAccountEmail, existingAccountPassword) + await page.fill(accountSelector.registrationFirstNameSelector, accountValue.newAccountFirstName); + await page.fill(accountSelector.registrationLastNameSelector, accountValue.newAccountLastName); + await page.fill(accountSelector.registrationEmailAddressSelector, uniqueEmail); + await page.fill(accountSelector.registrationPasswordSelector, existingAccountPassword); + await page.fill(accountSelector.registrationConfirmPasswordSelector, existingAccountPassword); - await page.goto(slugs.accountAddressBookSlug); - await page.locator(accountSelector.accountEditAddressButtons).first().click(); - await page.fill(accountSelector.registrationFirstNameSelector, accountValue.newChangedAddressFirstName); - await page.fill(accountSelector.registrationLastNameSelector, accountValue.newChangedAddressLastName); - await page.fill(accountSelector.accountTelephoneSelector, accountValue.newAddressTelephoneNumber); - await page.fill(accountSelector.accountStreetAddressSelector, accountValue.newAddressStreetAddress); - await page.fill(accountSelector.accountZipSelector, accountValue.newAddressZipCode); - await page.fill(accountSelector.accountCitySelector, accountValue.newAddressCityName); - await page.click(accountSelector.accountAddressSaveButtonSelector); + await page.click(accountSelector.registrationCreateAccountButtonSelector); - await expect(page.locator(`text=${accountExpected.accountAddressChangedNotificationText}`)).toBeVisible(); + const uniqueSuccessfulAccountCreationNotificationText = accountExpected.uniqueSuccessfulAccountCreationNotificationText; + await expect(page.locator(`text=${uniqueSuccessfulAccountCreationNotificationText}`)).toBeVisible(); - const accountPageTester = new PageTester(page, page.url()); - await accountPageTester.testPage(); + console.log(`Account created with credentials: email address "${uniqueEmail}" and password "${newAccountPassword}"`); }); + } - test('Subscribe and unsubscribe to newsletter', async ({ page }) => { - const account = new Account(page); - await account.login(existingAccountEmail, existingAccountPassword); + if (toggle.account.testAccountLogin) { + test('Login with an account', async ({page}) => { + const account = new Account(page); + await account.login(existingAccountEmail, existingAccountPassword); - await page.goto(slugs.accountNewsletterSubscriptionsSlug); + const accountPageTester = new PageTester(page, page.url()); + await accountPageTester.testPage(); + await expect(page.locator(`text=${existingAccountEmail}`)).toBeVisible(); + }); + } - await page.click(accountSelector.subscriptionCheckBoxSelector); - await page.click(accountSelector.accountSaveButtonSelector); - await expect(page.locator(`text=${accountExpected.accountNewsletterSubscribedNotificationText}`)).toBeVisible(); + test('Add new address on account', async ({page}) => { + const account = new Account(page); + await account.login(existingAccountEmail, existingAccountPassword); - await page.goto(slugs.accountNewsletterSubscriptionsSlug); + await page.goto(slugs.accountNewAddressSlug); + await page.fill(accountSelector.registrationFirstNameSelector, accountValue.newAccountFirstName); + await page.fill(accountSelector.registrationLastNameSelector, accountValue.newAccountLastName); + await page.fill(accountSelector.accountTelephoneSelector, accountValue.newAddressTelephoneNumber); + await page.fill(accountSelector.accountStreetAddressSelector, accountValue.newAddressStreetAddress); + await page.fill(accountSelector.accountZipSelector, accountValue.newAddressZipCode); + await page.fill(accountSelector.accountCitySelector, accountValue.newAddressCityName); + await page.selectOption(accountSelector.accountProvinceSelector, {value: accountValue.newAddressProvinceValue}); - await page.click(accountSelector.subscriptionCheckBoxSelector); - await page.click(accountSelector.accountSaveButtonSelector); - await expect(page.locator(`text=${accountExpected.accountNewsletterUnsubscribedNotificationText}`)).toBeVisible(); + await page.click(accountSelector.accountAddressSaveButtonSelector); - const accountPageTester = new PageTester(page, page.url()); - await accountPageTester.testPage(); - }); + await expect(page.locator(`text=${accountExpected.accountAddressChangedNotificationText}`)).toBeVisible(); - if(toggle.account.testAccountPageTitles.all) { - test('Test page titles and meta titles', async ({ page }) => { - const account = new Account(page); - await account.login(existingAccountEmail, existingAccountPassword); - - const accountPageTester = new PageTester(page, page.url()); - await accountPageTester.testPage(); - - // Test Account Information Page - await page.goto(slugs.accountChangeInformationSlug); - await expect(page).toHaveURL(new RegExp(`${slugs.accountChangeInformationSlug}.*`)); - await expect(page.locator(globalSelector.mainColumn)).toContainText(accountExpected.accountAccountInformationPageTitle); - - const accountInformationPageTester = new PageTester(page, page.url()); - await accountInformationPageTester.testPage(); - - // Test Address Book Page - await page.goto(slugs.accountAddressBookSlug); - await expect(page).toHaveURL(new RegExp(`${slugs.accountAddressBookSlug}.*`)); - await expect(page.locator(globalSelector.mainColumn)).toContainText(accountExpected.accountAddressBookPageTitle); - - const addressBookPageTester = new PageTester(page, page.url()); - await addressBookPageTester.testPage(); - - // Test Order History Page - await page.goto(slugs.accountOrderHistorySlug); - await expect(page).toHaveURL(new RegExp(`${slugs.accountOrderHistorySlug}.*`)); - await expect(page.locator(globalSelector.mainColumn)).toContainText(accountExpected.accountMyOrdersPageTitle); - - const orderHistoryPageTester = new PageTester(page, page.url()); - await orderHistoryPageTester.testPage(); - - // Test Downloads Page - await page.goto(slugs.accountDownloadsSlug); - await expect(page).toHaveURL(new RegExp(`${slugs.accountDownloadsSlug}.*`)); - await expect(page.locator(globalSelector.mainColumn)).toContainText(accountExpected.accountDownloadsPageTitle); - - const downloadsPageTester = new PageTester(page, page.url()); - await downloadsPageTester.testPage(); - - // Test Wishlist Page - await page.goto(slugs.accountWishlistSlug); - await expect(page).toHaveURL(new RegExp(`${slugs.accountWishlistSlug}.*`)); - await expect(page.locator(globalSelector.mainColumn)).toContainText(accountExpected.acccountMyWishlistPageTitle); - - const wishlistPageTester = new PageTester(page, page.url()); - await wishlistPageTester.testPage(); - - // Test Saved Payment Methods Page - await page.goto(slugs.accountSavedPaymentMethodsSlug); - await expect(page).toHaveURL(new RegExp(`${slugs.accountSavedPaymentMethodsSlug}.*`)); - await expect(page.locator(globalSelector.mainColumn)).toContainText(accountExpected.accountSavedPaymentMethodsPageTitle); - - const savedPaymentMethodsPageTester = new PageTester(page, page.url()); - await savedPaymentMethodsPageTester.testPage(); - - if(toggle.account.testAccountPageTitles.ProductReviewsTest) { - // Test Product Reviews Page - await page.goto(slugs.accountReviewsSlug); - await expect(page).toHaveURL(new RegExp(`${slugs.accountReviewsSlug}.*`)); - await expect(page.locator(globalSelector.mainColumn)).toContainText(accountExpected.accountProductReviewsPageTitle); - - const productReviewsPageTester = new PageTester(page, page.url()); - await productReviewsPageTester.testPage(); - } - - // Test Newsletter Subscriptions Page - await page.goto(slugs.accountNewsletterSubscriptionsSlug); - await expect(page).toHaveURL(new RegExp(`${slugs.accountNewsletterSubscriptionsSlug}.*`)); - await expect(page.locator(globalSelector.mainColumn)).toContainText(accountExpected.accountNewsletterSubscriptionsPageTitle); - - const newsletterSubscriptionsPageTester = new PageTester(page, page.url()); - await newsletterSubscriptionsPageTester.testPage(); - }); - } - - test('Update firstname and lastname on account', async ({ page }) => { - const account = new Account(page); - await account.login(existingAccountEmail, existingAccountPassword); - - await page.goto(slugs.accountEditSlug); - await page.fill(accountSelector.registrationFirstNameSelector, accountValue.newAccountLastName); - await page.fill(accountSelector.registrationLastNameSelector, accountValue.newAccountFirstName); - await page.click(accountSelector.accountSaveButtonSelector); - await expect(page.locator(`text=${accountExpected.accountInformationUpdatedNotificationText}`)).toBeVisible(); + const accountPageTester = new PageTester(page, page.url()); + await accountPageTester.testPage(); + }); - // Page test - const accountPageTester = new PageTester(page, page.url()); - await accountPageTester.testPage(); - }); + test('Edit address on account', async ({page}) => { + const account = new Account(page); + await account.login(existingAccountEmail, existingAccountPassword) - test('Delete address on account', async ({ page }) => { - const account = new Account(page); - await account.login(existingAccountEmail, existingAccountPassword); - page.on('dialog', async (dialog) => { - if (dialog.type() === 'confirm') { - await dialog.accept(); - } - }); + await page.goto(slugs.accountAddressBookSlug); + await page.locator(accountSelector.accountEditAddressButtons).first().click(); + await page.fill(accountSelector.registrationFirstNameSelector, accountValue.newChangedAddressFirstName); + await page.fill(accountSelector.registrationLastNameSelector, accountValue.newChangedAddressLastName); + await page.fill(accountSelector.accountTelephoneSelector, accountValue.newAddressTelephoneNumber); + await page.fill(accountSelector.accountStreetAddressSelector, accountValue.newAddressStreetAddress); + await page.fill(accountSelector.accountZipSelector, accountValue.newAddressZipCode); + await page.fill(accountSelector.accountCitySelector, accountValue.newAddressCityName); + await page.click(accountSelector.accountAddressSaveButtonSelector); + + await expect(page.locator(`text=${accountExpected.accountAddressChangedNotificationText}`)).toBeVisible(); + + const accountPageTester = new PageTester(page, page.url()); + await accountPageTester.testPage(); + }); + + test('Subscribe and unsubscribe to newsletter', async ({page}) => { + const account = new Account(page); + await account.login(existingAccountEmail, existingAccountPassword); + + await page.goto(slugs.accountNewsletterSubscriptionsSlug); + + await page.click(accountSelector.subscriptionCheckBoxSelector); + await page.click(accountSelector.accountSaveButtonSelector); + await expect(page.locator(`text=${accountExpected.accountNewsletterSubscribedNotificationText}`)).toBeVisible(); + + await page.goto(slugs.accountNewsletterSubscriptionsSlug); + + await page.click(accountSelector.subscriptionCheckBoxSelector); + await page.click(accountSelector.accountSaveButtonSelector); + await expect(page.locator(`text=${accountExpected.accountNewsletterUnsubscribedNotificationText}`)).toBeVisible(); + + const accountPageTester = new PageTester(page, page.url()); + await accountPageTester.testPage(); + }); + + if (toggle.account.testAccountPageTitles.all) { + test('Test page titles and meta titles', async ({page}) => { + const account = new Account(page); + await account.login(existingAccountEmail, existingAccountPassword); + + const accountPageTester = new PageTester(page, page.url()); + await accountPageTester.testPage(); + + // Test Account Information Page + await page.goto(slugs.accountChangeInformationSlug); + await expect(page).toHaveURL(new RegExp(`${slugs.accountChangeInformationSlug}.*`)); + await expect(page.locator(globalSelector.mainColumn)).toContainText(accountExpected.accountAccountInformationPageTitle); + + const accountInformationPageTester = new PageTester(page, page.url()); + await accountInformationPageTester.testPage(); + + // Test Address Book Page + await page.goto(slugs.accountAddressBookSlug); + await expect(page).toHaveURL(new RegExp(`${slugs.accountAddressBookSlug}.*`)); + await expect(page.locator(globalSelector.mainColumn)).toContainText(accountExpected.accountAddressBookPageTitle); + + const addressBookPageTester = new PageTester(page, page.url()); + await addressBookPageTester.testPage(); + + // Test Order History Page + await page.goto(slugs.accountOrderHistorySlug); + await expect(page).toHaveURL(new RegExp(`${slugs.accountOrderHistorySlug}.*`)); + await expect(page.locator(globalSelector.mainColumn)).toContainText(accountExpected.accountMyOrdersPageTitle); + + const orderHistoryPageTester = new PageTester(page, page.url()); + await orderHistoryPageTester.testPage(); + + // Test Downloads Page + await page.goto(slugs.accountDownloadsSlug); + await expect(page).toHaveURL(new RegExp(`${slugs.accountDownloadsSlug}.*`)); + await expect(page.locator(globalSelector.mainColumn)).toContainText(accountExpected.accountDownloadsPageTitle); + + const downloadsPageTester = new PageTester(page, page.url()); + await downloadsPageTester.testPage(); + + // Test Wishlist Page + await page.goto(slugs.accountWishlistSlug); + await expect(page).toHaveURL(new RegExp(`${slugs.accountWishlistSlug}.*`)); + await expect(page.locator(globalSelector.mainColumn)).toContainText(accountExpected.acccountMyWishlistPageTitle); + + const wishlistPageTester = new PageTester(page, page.url()); + await wishlistPageTester.testPage(); - await page.goto(slugs.accountAddressBookSlug); + // Test Saved Payment Methods Page + await page.goto(slugs.accountSavedPaymentMethodsSlug); + await expect(page).toHaveURL(new RegExp(`${slugs.accountSavedPaymentMethodsSlug}.*`)); + await expect(page.locator(globalSelector.mainColumn)).toContainText(accountExpected.accountSavedPaymentMethodsPageTitle); - await page.locator(accountSelector.accountDeleteAddressButtons).first().click(); - await page.waitForTimeout(2000); - await expect(page.locator(`text=${accountExpected.accountAddressDeletedNotificationText}`)).toBeVisible(); + const savedPaymentMethodsPageTester = new PageTester(page, page.url()); + await savedPaymentMethodsPageTester.testPage(); - const accountPageTester = new PageTester(page, page.url()); - await accountPageTester.testPage(); + if (toggle.account.testAccountPageTitles.ProductReviewsTest) { + // Test Product Reviews Page + await page.goto(slugs.accountReviewsSlug); + await expect(page).toHaveURL(new RegExp(`${slugs.accountReviewsSlug}.*`)); + await expect(page.locator(globalSelector.mainColumn)).toContainText(accountExpected.accountProductReviewsPageTitle); + + const productReviewsPageTester = new PageTester(page, page.url()); + await productReviewsPageTester.testPage(); + } + + // Test Newsletter Subscriptions Page + await page.goto(slugs.accountNewsletterSubscriptionsSlug); + await expect(page).toHaveURL(new RegExp(`${slugs.accountNewsletterSubscriptionsSlug}.*`)); + await expect(page.locator(globalSelector.mainColumn)).toContainText(accountExpected.accountNewsletterSubscriptionsPageTitle); + + const newsletterSubscriptionsPageTester = new PageTester(page, page.url()); + await newsletterSubscriptionsPageTester.testPage(); + }); + } + + test('Update firstname and lastname on account', async ({page}) => { + const account = new Account(page); + await account.login(existingAccountEmail, existingAccountPassword); + + await page.goto(slugs.accountEditSlug); + await page.fill(accountSelector.registrationFirstNameSelector, accountValue.newAccountLastName); + await page.fill(accountSelector.registrationLastNameSelector, accountValue.newAccountFirstName); + await page.click(accountSelector.accountSaveButtonSelector); + await expect(page.locator(`text=${accountExpected.accountInformationUpdatedNotificationText}`)).toBeVisible(); + + // Page test + const accountPageTester = new PageTester(page, page.url()); + await accountPageTester.testPage(); + }); + + test('Delete address on account', async ({page}) => { + const account = new Account(page); + await account.login(existingAccountEmail, existingAccountPassword); + page.on('dialog', async (dialog) => { + if (dialog.type() === 'confirm') { + await dialog.accept(); + } }); - if(toggle.account.testAccountPasswordChange) { - test('Change password for account', async ({ page }) => { - // Change password - const changePassword = async (currentPassword: string, newPassword: string) => { - await page.goto(slugs.changePasswordSlug); - await page.click(accountSelector.changePasswordLabel); - await page.fill(accountSelector.currentPasswordFieldSelector, currentPassword); - await page.fill(accountSelector.registrationPasswordSelector, newPassword); - await page.fill(accountSelector.registrationConfirmPasswordSelector, newPassword); - await page.click(accountSelector.accountSaveButtonSelector); - await expect(page.locator(`text=${accountExpected.accountInformationUpdatedNotificationText}`)).toBeVisible(); - }; - - // Initial login and password change - const account = new Account(page); - await account.login(existingAccountEmail, existingAccountChangedPassword); - await changePassword(existingAccountPassword, existingAccountChangedPassword); - - // Verify login with new password - await account.login(existingAccountEmail, existingAccountChangedPassword); - await changePassword(existingAccountChangedPassword, existingAccountPassword); - - // Page test - const accountPageTester = new PageTester(page, page.url()); - await accountPageTester.testPage(); - }); - } - - test('Logout with an account', async ({ page }) => { - const account = new Account(page); - await account.login(existingAccountEmail, existingAccountPassword); - - await account.logout(); - const accountPageTester = new PageTester(page, page.url()) - await accountPageTester.testPage(); + await page.goto(slugs.accountAddressBookSlug); + + await page.locator(accountSelector.accountDeleteAddressButtons).first().click(); + await page.waitForTimeout(2000); + await expect(page.locator(`text=${accountExpected.accountAddressDeletedNotificationText}`)).toBeVisible(); + + const accountPageTester = new PageTester(page, page.url()); + await accountPageTester.testPage(); + }); + + if (toggle.account.testAccountPasswordChange) { + test('Change password for account', async ({page}) => { + // Change password + const changePassword = async (currentPassword: string, newPassword: string) => { + await page.goto(slugs.changePasswordSlug); + await page.click(accountSelector.changePasswordLabel); + await page.fill(accountSelector.currentPasswordFieldSelector, currentPassword); + await page.fill(accountSelector.registrationPasswordSelector, newPassword); + await page.fill(accountSelector.registrationConfirmPasswordSelector, newPassword); + await page.click(accountSelector.accountSaveButtonSelector); + await expect(page.locator(`text=${accountExpected.accountInformationUpdatedNotificationText}`)).toBeVisible(); + }; + + // Initial login and password change + const account = new Account(page); + await account.login(existingAccountEmail, existingAccountChangedPassword); + await changePassword(existingAccountPassword, existingAccountChangedPassword); + + // Verify login with new password + await account.login(existingAccountEmail, existingAccountChangedPassword); + await changePassword(existingAccountChangedPassword, existingAccountPassword); + + // Page test + const accountPageTester = new PageTester(page, page.url()); + await accountPageTester.testPage(); }); + } + + test('Logout with an account', async ({page}) => { + const account = new Account(page); + await account.login(existingAccountEmail, existingAccountPassword); + + await account.logout(); + const accountPageTester = new PageTester(page, page.url()) + await accountPageTester.testPage(); + }); }); diff --git a/tests/base/config/test-toggles.example.json b/tests/base/config/test-toggles.example.json index ca68f70..439d3e3 100644 --- a/tests/base/config/test-toggles.example.json +++ b/tests/base/config/test-toggles.example.json @@ -1,16 +1,15 @@ { - "testForPageErrors": false, - "account": { - "testAccountCreation": false, - "testAccountLogin": true, - "testAccountPasswordChange": true, - "testAccountPageTitles": - { - "all": true, - "ProductReviewsTest": false - } - }, - "minicart": { - "testCheckoutButton": true + "testForPageErrors": false, + "account": { + "testAccountCreation": false, + "testAccountLogin": true, + "testAccountPasswordChange": true, + "testAccountPageTitles": { + "all": true, + "ProductReviewsTest": false } -} \ No newline at end of file + }, + "minicart": { + "testCheckoutButton": true + } +} diff --git a/tests/base/config/test-toggles.json b/tests/base/config/test-toggles.json index 874be4b..5be554f 100644 --- a/tests/base/config/test-toggles.json +++ b/tests/base/config/test-toggles.json @@ -1,19 +1,18 @@ { - "testForPageErrors": false, - "account": { - "testAccountCreation": false, - "testAccountLogin": true, - "testAccountPasswordChange": true, - "testAccountPageTitles": - { - "all": true, - "ProductReviewsTest": false - } - }, - "minicart": { - "testMiniCartCheckoutButton": true, - "testMiniCartLink": true, - "testMiniCartQuantity": true, - "testMiniCartDeletion": true + "testForPageErrors": false, + "account": { + "testAccountCreation": false, + "testAccountLogin": true, + "testAccountPasswordChange": true, + "testAccountPageTitles": { + "all": true, + "ProductReviewsTest": false } -} \ No newline at end of file + }, + "minicart": { + "testMiniCartCheckoutButton": true, + "testMiniCartLink": true, + "testMiniCartQuantity": true, + "testMiniCartDeletion": true + } +} diff --git a/tests/base/contact.spec.ts b/tests/base/contact.spec.ts index 148a0f8..9b2d43b 100644 --- a/tests/base/contact.spec.ts +++ b/tests/base/contact.spec.ts @@ -1,6 +1,6 @@ -import { test, expect, selectors } from '@playwright/test'; -import { PageTester } from './utils/PageTester'; -import { Contact } from './utils/Contact'; +import {test, expect, selectors} from '@playwright/test'; +import {PageTester} from './utils/PageTester'; +import {Contact} from './utils/Contact'; import slugs from './fixtures/before/slugs.json'; import contactSelector from './fixtures/during/selectors/contact.json'; import globalSelector from './fixtures/during/selectors/global.json'; @@ -8,25 +8,24 @@ import contactValue from './fixtures/during/input-values/contact.json'; import accountExpected from './fixtures/verify/expects/contact.json'; test.describe('Test user flow', () => { + test('Send contactform', async ({page}) => { + const randomNumber = Math.floor(Math.random() * 10000000); + const emailHandle = contactValue.contactEmailHandle; + const emailHost = contactValue.contactEmailHost; + const uniqueEmail = `${emailHandle}${randomNumber}@${emailHost}`; - test('Send contactform', async ({ page }) => { - const randomNumber = Math.floor(Math.random() * 10000000); - const emailHandle = contactValue.contactEmailHandle; - const emailHost = contactValue.contactEmailHost; - const uniqueEmail = `${emailHandle}${randomNumber}@${emailHost}`; + await page.goto(slugs.contactSlug); - await page.goto(slugs.contactSlug); + await page.fill(contactSelector.contactNameSelector, contactValue.contactName); + await page.fill(contactSelector.contactEmailSelector, uniqueEmail); + await page.fill(contactSelector.contactTelephoneSelector, contactValue.contactTelephoneNumber); + await page.fill(contactSelector.contactCommentSelector, contactValue.contactComment); - await page.fill(contactSelector.contactNameSelector, contactValue.contactName); - await page.fill(contactSelector.contactEmailSelector, uniqueEmail); - await page.fill(contactSelector.contactTelephoneSelector, contactValue.contactTelephoneNumber); - await page.fill(contactSelector.contactCommentSelector, contactValue.contactComment); + await page.click(contactSelector.contactButtonSelectorName); - await page.click(contactSelector.contactButtonSelectorName); + const contactFormSuccessNotificationText = accountExpected.contactFormSuccessNotificationText; + await expect(page.locator(`text=${contactFormSuccessNotificationText}`)).toBeVisible(); - const contactFormSuccessNotificationText = accountExpected.contactFormSuccessNotificationText; - await expect(page.locator(`text=${contactFormSuccessNotificationText}`)).toBeVisible(); - - console.log(`Contact form submitted by email address "${uniqueEmail}"`); - }); + console.log(`Contact form submitted by email address "${uniqueEmail}"`); + }); }); diff --git a/tests/base/fixtures/before/slugs.json b/tests/base/fixtures/before/slugs.json index 0f6e29d..c32e8ef 100644 --- a/tests/base/fixtures/before/slugs.json +++ b/tests/base/fixtures/before/slugs.json @@ -1,28 +1,28 @@ { - "homepageSlug": "/", - "categorySlug": "/women.html", - "simpleProductSlug": "/push-it-messenger-bag.html", - "configurableProductSlug": "/inez-full-zip-jacket.html", - "cartSlug": "/checkout/cart", - "checkoutSlug": "/checkout", - "searchSlug": "/catalogsearch/result/?q=search", - "loginSlug": "/customer/account/login/", - "forgotPasswordSlug": "/customer/account/forgotpassword/", - "accountCreationSlug": "/customer/account/create/", - "accountEditSlug": "/customer/account/edit/", - "afterAccountCreationSlug": "/customer/account/", - "afterLoginSlug": "/customer/account/", - "afterLogoutSlug": "/customer/account/logoutSuccess/", - "changePasswordSlug": "/customer/account/edit/changepass/", - "accountChangeInformationSlug": "/customer/account/edit/", - "accountAddressBookSlug": "/customer/address/", - "accountNewAddressSlug": "/customer/address/new/", - "accountOrderHistorySlug": "/sales/order/history/", - "accountDownloadsSlug": "/downloadable/customer/products/", - "accountWishlistSlug": "/wishlist/", - "accountSavedPaymentMethodsSlug": "vault/cards/listaction/", - "accountReviewsSlug": "/review/customer/", - "accountNewsletterSubscriptionsSlug": "/newsletter/manage/", - "contactSlug": "/contact/", - "productQuantityChangeSlug": "/checkout/cart/configure/id/" -} \ No newline at end of file + "homepageSlug": "/", + "categorySlug": "/women.html", + "simpleProductSlug": "/push-it-messenger-bag.html", + "configurableProductSlug": "/inez-full-zip-jacket.html", + "cartSlug": "/checkout/cart", + "checkoutSlug": "/checkout", + "searchSlug": "/catalogsearch/result/?q=search", + "loginSlug": "/customer/account/login/", + "forgotPasswordSlug": "/customer/account/forgotpassword/", + "accountCreationSlug": "/customer/account/create/", + "accountEditSlug": "/customer/account/edit/", + "afterAccountCreationSlug": "/customer/account/", + "afterLoginSlug": "/customer/account/", + "afterLogoutSlug": "/customer/account/logoutSuccess/", + "changePasswordSlug": "/customer/account/edit/changepass/", + "accountChangeInformationSlug": "/customer/account/edit/", + "accountAddressBookSlug": "/customer/address/", + "accountNewAddressSlug": "/customer/address/new/", + "accountOrderHistorySlug": "/sales/order/history/", + "accountDownloadsSlug": "/downloadable/customer/products/", + "accountWishlistSlug": "/wishlist/", + "accountSavedPaymentMethodsSlug": "vault/cards/listaction/", + "accountReviewsSlug": "/review/customer/", + "accountNewsletterSubscriptionsSlug": "/newsletter/manage/", + "contactSlug": "/contact/", + "productQuantityChangeSlug": "/checkout/cart/configure/id/" +} diff --git a/tests/base/fixtures/before/websites.json b/tests/base/fixtures/before/websites.json index 92d6c19..54ae28b 100644 --- a/tests/base/fixtures/before/websites.json +++ b/tests/base/fixtures/before/websites.json @@ -1,3 +1,3 @@ { - "playwrightWebsite": "https://playwright.dev/" -} \ No newline at end of file + "playwrightWebsite": "https://playwright.dev/" +} diff --git a/tests/base/fixtures/during/input-values/account.json b/tests/base/fixtures/during/input-values/account.json index 4b7f518..e90f27a 100644 --- a/tests/base/fixtures/during/input-values/account.json +++ b/tests/base/fixtures/during/input-values/account.json @@ -1,19 +1,19 @@ { - "newAccountFirstName": "John", - "newAccountLastName": "Doe", - "newAccountEmailHandle": "test-user", - "newAccountEmailHost": "gmail.com", - "newAddressCompany": "ACME Company", - "newAddressTelephoneNumber": "0600000000", - "newAddressStreetAddress": "Teststraat 1", - "newAddressZipCode": "1234AA", - "newAddressCityName": "Testdam", - "newAddressProvinceValue": "1", - "newChangedAddressFirstName": "Jane", - "newChangedAddressLastName": "Dont", - "newChangedAddressCompany": "Disney Company", - "newChangedAddressTelephoneNumber": "0612345678", - "newChangedAddressStreetAddress": "Straat Der Testen 100", - "newChangedAddressZipCode": "4321 BB", - "newChangedAddressCityName": "Testdorp" -} \ No newline at end of file + "newAccountFirstName": "John", + "newAccountLastName": "Doe", + "newAccountEmailHandle": "test-user", + "newAccountEmailHost": "gmail.com", + "newAddressCompany": "ACME Company", + "newAddressTelephoneNumber": "0600000000", + "newAddressStreetAddress": "Teststraat 1", + "newAddressZipCode": "1234AA", + "newAddressCityName": "Testdam", + "newAddressProvinceValue": "1", + "newChangedAddressFirstName": "Jane", + "newChangedAddressLastName": "Dont", + "newChangedAddressCompany": "Disney Company", + "newChangedAddressTelephoneNumber": "0612345678", + "newChangedAddressStreetAddress": "Straat Der Testen 100", + "newChangedAddressZipCode": "4321 BB", + "newChangedAddressCityName": "Testdorp" +} diff --git a/tests/base/fixtures/during/input-values/contact.json b/tests/base/fixtures/during/input-values/contact.json index 7947765..68d92e9 100644 --- a/tests/base/fixtures/during/input-values/contact.json +++ b/tests/base/fixtures/during/input-values/contact.json @@ -1,7 +1,7 @@ { - "contactName": "John Doe", - "contactEmailHandle": "test-user", - "contactEmailHost": "gmail.com", - "contactTelephoneNumber": "0600000000", - "contactComment": "Is this my question?" -} \ No newline at end of file + "contactName": "John Doe", + "contactEmailHandle": "test-user", + "contactEmailHost": "gmail.com", + "contactTelephoneNumber": "0600000000", + "contactComment": "Is this my question?" +} diff --git a/tests/base/fixtures/during/input-values/search.json b/tests/base/fixtures/during/input-values/search.json index 342d35f..e6b3db2 100644 --- a/tests/base/fixtures/during/input-values/search.json +++ b/tests/base/fixtures/during/input-values/search.json @@ -1,3 +1,3 @@ { - "searchProductName": "Bella Tank" -} \ No newline at end of file + "searchProductName": "Bella Tank" +} diff --git a/tests/base/fixtures/during/selectors/account.json b/tests/base/fixtures/during/selectors/account.json index c9e0236..a5ad6cf 100644 --- a/tests/base/fixtures/during/selectors/account.json +++ b/tests/base/fixtures/during/selectors/account.json @@ -1,28 +1,28 @@ { - "registrationFirstNameSelector": "#firstname", - "registrationLastNameSelector": "#lastname", - "registrationEmailAddressSelector": "#email_address", - "registrationPasswordSelector": "#password", - "registrationConfirmPasswordSelector": "#password-confirmation", - "registrationCreateAccountButtonSelector": "button[title='Create an Account']", - "loginEmailAddressSelector": "#email", - "loginPasswordSelector": "#pass", - "loginButtonSelectorName": "button[name='send']", - "accountSaveButtonSelector": "button[title='Save']", - "logoutMenuItemPosition": 8, - "accountMenuItemsSelector": ".nav.items .nav.item a", - "changePasswordLabel": "#change-password", - "currentPasswordFieldSelector": "#current-password", - "newPasswordFieldSelector": "#current-password", - "accountAddressSaveButtonSelector": "button[title='Save Address']", - "accountTelephoneSelector": "#telephone", - "accountCompanySelector": "#company", - "accountStreetAddressSelector": "#street_1", - "accountZipSelector": "#zip", - "accountCitySelector": "#city", - "accountProvinceSelector": "select#region_id", - "accountAddAddressButton": "a.action.add", - "accountEditAddressButtons": "a.action.edit", - "accountDeleteAddressButtons": "a.action.delete", - "subscriptionCheckBoxSelector": "#subscription" -} \ No newline at end of file + "registrationFirstNameSelector": "#firstname", + "registrationLastNameSelector": "#lastname", + "registrationEmailAddressSelector": "#email_address", + "registrationPasswordSelector": "#password", + "registrationConfirmPasswordSelector": "#password-confirmation", + "registrationCreateAccountButtonSelector": "button[title='Create an Account']", + "loginEmailAddressSelector": "#email", + "loginPasswordSelector": "#pass", + "loginButtonSelectorName": "button[name='send']", + "accountSaveButtonSelector": "button[title='Save']", + "logoutMenuItemPosition": 8, + "accountMenuItemsSelector": ".nav.items .nav.item a", + "changePasswordLabel": "#change-password", + "currentPasswordFieldSelector": "#current-password", + "newPasswordFieldSelector": "#current-password", + "accountAddressSaveButtonSelector": "button[title='Save Address']", + "accountTelephoneSelector": "#telephone", + "accountCompanySelector": "#company", + "accountStreetAddressSelector": "#street_1", + "accountZipSelector": "#zip", + "accountCitySelector": "#city", + "accountProvinceSelector": "select#region_id", + "accountAddAddressButton": "a.action.add", + "accountEditAddressButtons": "a.action.edit", + "accountDeleteAddressButtons": "a.action.delete", + "subscriptionCheckBoxSelector": "#subscription" +} diff --git a/tests/base/fixtures/during/selectors/contact.json b/tests/base/fixtures/during/selectors/contact.json index e49f420..36433fe 100644 --- a/tests/base/fixtures/during/selectors/contact.json +++ b/tests/base/fixtures/during/selectors/contact.json @@ -1,7 +1,7 @@ { - "contactNameSelector": ".form.contact #name", - "contactEmailSelector": ".form.contact #email", - "contactTelephoneSelector": ".form.contact #telephone", - "contactCommentSelector": ".form.contact #comment", - "contactButtonSelectorName": ".form.contact button[type='submit']" -} \ No newline at end of file + "contactNameSelector": ".form.contact #name", + "contactEmailSelector": ".form.contact #email", + "contactTelephoneSelector": ".form.contact #telephone", + "contactCommentSelector": ".form.contact #comment", + "contactButtonSelectorName": ".form.contact button[type='submit']" +} diff --git a/tests/base/fixtures/during/selectors/example.json b/tests/base/fixtures/during/selectors/example.json index 7d81cf6..4666174 100644 --- a/tests/base/fixtures/during/selectors/example.json +++ b/tests/base/fixtures/during/selectors/example.json @@ -1,3 +1,3 @@ { - "getStartedSelectorText": "Get started" -} \ No newline at end of file + "getStartedSelectorText": "Get started" +} diff --git a/tests/base/fixtures/during/selectors/global.json b/tests/base/fixtures/during/selectors/global.json index daf372f..87eae0e 100644 --- a/tests/base/fixtures/during/selectors/global.json +++ b/tests/base/fixtures/during/selectors/global.json @@ -1,4 +1,4 @@ { - "mainColumn": ".column.main", - "successMessages": ".message.success" -} \ No newline at end of file + "mainColumn": ".column.main", + "successMessages": ".message.success" +} diff --git a/tests/base/fixtures/during/selectors/minicart.json b/tests/base/fixtures/during/selectors/minicart.json index 8ede7a1..f46e54e 100644 --- a/tests/base/fixtures/during/selectors/minicart.json +++ b/tests/base/fixtures/during/selectors/minicart.json @@ -1,9 +1,9 @@ { - "miniCartIconSelector": "#menu-cart-icon", - "miniCartDrawerTitleSelector": "#cart-drawer-title", - "miniCartCheckoutButtonSelector": "a.btn.btn-primary[href$='/checkout/']", - "miniCartCartLinkSelector": "a.underline[href$='/checkout/cart/']", - "miniCartQuantityButtonSelector": "a[href*='checkout/cart/configure/']", - "miniCartDeleteProductButtonSelector": "button[aria-label^='Remove product']", - "miniCartQuantitySelector": "span[x-html='item.qty']" -} \ No newline at end of file + "miniCartIconSelector": "#menu-cart-icon", + "miniCartDrawerTitleSelector": "#cart-drawer-title", + "miniCartCheckoutButtonSelector": "a.btn.btn-primary[href$='/checkout/']", + "miniCartCartLinkSelector": "a.underline[href$='/checkout/cart/']", + "miniCartQuantityButtonSelector": "a[href*='checkout/cart/configure/']", + "miniCartDeleteProductButtonSelector": "button[aria-label^='Remove product']", + "miniCartQuantitySelector": "span[x-html='item.qty']" +} diff --git a/tests/base/fixtures/during/selectors/product-page.json b/tests/base/fixtures/during/selectors/product-page.json index 9187bc7..36be591 100644 --- a/tests/base/fixtures/during/selectors/product-page.json +++ b/tests/base/fixtures/during/selectors/product-page.json @@ -1,4 +1,4 @@ { - "addToCartButtonSelector": "#product-addtocart-button", - "productQuantityInputSelector": "input[name='qty'][type='number']" -} \ No newline at end of file + "addToCartButtonSelector": "#product-addtocart-button", + "productQuantityInputSelector": "input[name='qty'][type='number']" +} diff --git a/tests/base/fixtures/verify/expects/account.json b/tests/base/fixtures/verify/expects/account.json index 80a64a6..e770511 100644 --- a/tests/base/fixtures/verify/expects/account.json +++ b/tests/base/fixtures/verify/expects/account.json @@ -1,26 +1,26 @@ { - "uniqueSuccessfulAccountCreationNotificationText": "Thank you for registering with Main Website Store.", - "accountInformationUpdatedNotificationText": "You saved the account information.", - "accountAddressChangedNotificationText": "You saved the address.", - "accountAddressDeletedNotificationText": "You deleted the address.", - "accountNewsletterSubscribedNotificationText": "We have saved your subscription.", - "accountNewsletterUnsubscribedNotificationText": "We have removed your newsletter subscription.", - "accountDashboardTitle": "Account Information", - "accountAccountInformationTitle": "Account Information", - "accountAddressBookTitle": "Address Book", - "accountMyOrdersTitle": "My Orders", - "accountDownloadsTitle": "Downloads", - "acccountMyWishlistTitle": "My Wishlist", - "accountSavedPaymentMethodsTitle": "Saved Payment Methods", - "accountProductReviewsTitle": "Product Reviews", - "accountNewsletterSubscriptionsTitle": "Newsletter Subscriptions", - "accountDashboardPageTitle": "Account Information", - "accountAccountInformationPageTitle": "Account Information", - "accountAddressBookPageTitle": "Default Addresses", - "accountMyOrdersPageTitle": "My Orders", - "accountDownloadsPageTitle": "My Downloadable Products", - "acccountMyWishlistPageTitle": "", - "accountSavedPaymentMethodsPageTitle": "", - "accountProductReviewsPageTitle": "Product Reviews", - "accountNewsletterSubscriptionsPageTitle": "Subscription option" -} \ No newline at end of file + "uniqueSuccessfulAccountCreationNotificationText": "Thank you for registering with Main Website Store.", + "accountInformationUpdatedNotificationText": "You saved the account information.", + "accountAddressChangedNotificationText": "You saved the address.", + "accountAddressDeletedNotificationText": "You deleted the address.", + "accountNewsletterSubscribedNotificationText": "We have saved your subscription.", + "accountNewsletterUnsubscribedNotificationText": "We have removed your newsletter subscription.", + "accountDashboardTitle": "Account Information", + "accountAccountInformationTitle": "Account Information", + "accountAddressBookTitle": "Address Book", + "accountMyOrdersTitle": "My Orders", + "accountDownloadsTitle": "Downloads", + "acccountMyWishlistTitle": "My Wishlist", + "accountSavedPaymentMethodsTitle": "Saved Payment Methods", + "accountProductReviewsTitle": "Product Reviews", + "accountNewsletterSubscriptionsTitle": "Newsletter Subscriptions", + "accountDashboardPageTitle": "Account Information", + "accountAccountInformationPageTitle": "Account Information", + "accountAddressBookPageTitle": "Default Addresses", + "accountMyOrdersPageTitle": "My Orders", + "accountDownloadsPageTitle": "My Downloadable Products", + "acccountMyWishlistPageTitle": "", + "accountSavedPaymentMethodsPageTitle": "", + "accountProductReviewsPageTitle": "Product Reviews", + "accountNewsletterSubscriptionsPageTitle": "Subscription option" +} diff --git a/tests/base/fixtures/verify/expects/contact.json b/tests/base/fixtures/verify/expects/contact.json index 6a3771f..8716e20 100644 --- a/tests/base/fixtures/verify/expects/contact.json +++ b/tests/base/fixtures/verify/expects/contact.json @@ -1,3 +1,3 @@ { - "contactFormSuccessNotificationText": "Thanks for contacting us with your comments and questions. We'll respond to you very soon." -} \ No newline at end of file + "contactFormSuccessNotificationText": "Thanks for contacting us with your comments and questions. We'll respond to you very soon." +} diff --git a/tests/base/fixtures/verify/expects/example.json b/tests/base/fixtures/verify/expects/example.json index 77b9702..462bb5b 100644 --- a/tests/base/fixtures/verify/expects/example.json +++ b/tests/base/fixtures/verify/expects/example.json @@ -1,4 +1,4 @@ { - "playwrightHeader": "Installation", - "playwrightPageTitle": "Playwright" -} \ No newline at end of file + "playwrightHeader": "Installation", + "playwrightPageTitle": "Playwright" +} diff --git a/tests/base/fixtures/verify/expects/global.json b/tests/base/fixtures/verify/expects/global.json index ac6e2af..28a7a95 100644 --- a/tests/base/fixtures/verify/expects/global.json +++ b/tests/base/fixtures/verify/expects/global.json @@ -1,3 +1,3 @@ { - "maxPageLoadTimeInMs": 2000 -} \ No newline at end of file + "maxPageLoadTimeInMs": 2000 +} diff --git a/tests/base/fixtures/verify/expects/minicart.json b/tests/base/fixtures/verify/expects/minicart.json index 47fd8db..7aaeb32 100644 --- a/tests/base/fixtures/verify/expects/minicart.json +++ b/tests/base/fixtures/verify/expects/minicart.json @@ -1,4 +1,4 @@ { - "productQuantity": "2", - "productDeletedFromCartNotificationText": "You removed the item." -} \ No newline at end of file + "productQuantity": "2", + "productDeletedFromCartNotificationText": "You removed the item." +} diff --git a/tests/base/fixtures/verify/expects/product-page.json b/tests/base/fixtures/verify/expects/product-page.json index 6dca584..c2cb6df 100644 --- a/tests/base/fixtures/verify/expects/product-page.json +++ b/tests/base/fixtures/verify/expects/product-page.json @@ -1,3 +1,3 @@ { - "productAddedToCartNotificationText": "You added Push It Messenger Bag to your" + "productAddedToCartNotificationText": "You added Push It Messenger Bag to your" } diff --git a/tests/base/minicart.spec.ts b/tests/base/minicart.spec.ts index 82f1ab2..d70b5ce 100644 --- a/tests/base/minicart.spec.ts +++ b/tests/base/minicart.spec.ts @@ -1,63 +1,60 @@ -import { test, expect, selectors } from '@playwright/test'; -import { Cart } from './utils/Cart'; +import {test, expect, selectors} from '@playwright/test'; +import {Cart} from './utils/Cart'; import toggle from './config/test-toggles.json'; import slugs from './fixtures/before/slugs.json'; import globalSelector from './fixtures/during/selectors/global.json'; - import miniCartSelector from './fixtures/during/selectors/minicart.json'; import miniCartExpected from './fixtures/verify/expects/minicart.json'; -import productSelector from './fixtures/during/selectors/product-page.json'; - -if(toggle.minicart.testMiniCartCheckoutButton) { - test('Test minicart to checkout', async ({ page }) => { - const cart = new Cart(page); - await cart.addSimpleProductToCart(slugs.simpleProductSlug); - await cart.openMiniCart(); +if (toggle.minicart.testMiniCartCheckoutButton) { + test('Test minicart to checkout', async ({page}) => { + const cart = new Cart(page); + await cart.addSimpleProductToCart(slugs.simpleProductSlug); + await cart.openMiniCart(); - await page.click(miniCartSelector.miniCartCheckoutButtonSelector); - await expect(page).toHaveURL(new RegExp(`${slugs.checkoutSlug}.*`)); - }); + await page.click(miniCartSelector.miniCartCheckoutButtonSelector); + await expect(page).toHaveURL(new RegExp(`${slugs.checkoutSlug}.*`)); + }); } -if(toggle.minicart.testMiniCartLink) { - test('Test minicart to cart', async ({ page }) => { - const cart = new Cart(page); - await cart.addSimpleProductToCart(slugs.simpleProductSlug); - await cart.openMiniCart(); +if (toggle.minicart.testMiniCartLink) { + test('Test minicart to cart', async ({page}) => { + const cart = new Cart(page); + await cart.addSimpleProductToCart(slugs.simpleProductSlug); + await cart.openMiniCart(); - await page.click(miniCartSelector.miniCartCartLinkSelector); - await expect(page).toHaveURL(new RegExp(`${slugs.cartSlug}.*`)); - }); + await page.click(miniCartSelector.miniCartCartLinkSelector); + await expect(page).toHaveURL(new RegExp(`${slugs.cartSlug}.*`)); + }); } -if(toggle.minicart.testMiniCartQuantity) { - test('Test minicart quantity change', async ({ page }) => { - const cart = new Cart(page); - await cart.addSimpleProductToCart(slugs.simpleProductSlug); - await cart.openMiniCart(); - await page.click(miniCartSelector.miniCartQuantityButtonSelector); +if (toggle.minicart.testMiniCartQuantity) { + test('Test minicart quantity change', async ({page}) => { + const cart = new Cart(page); + await cart.addSimpleProductToCart(slugs.simpleProductSlug); + await cart.openMiniCart(); + await page.click(miniCartSelector.miniCartQuantityButtonSelector); - await expect(page).toHaveURL(new RegExp(`${slugs.productQuantityChangeSlug}.*`)); - await page.fill(productSelector.productQuantityInputSelector, miniCartExpected.productQuantity); - await page.click(productSelector.addToCartButtonSelector); + await expect(page).toHaveURL(new RegExp(`${slugs.productQuantityChangeSlug}.*`)); + await page.fill(productSelector.productQuantityInputSelector, miniCartExpected.productQuantity); + await page.click(productSelector.addToCartButtonSelector); - await cart.openMiniCart(); - await expect(page.locator(miniCartSelector.miniCartQuantitySelector)).toContainText(miniCartExpected.productQuantity); + await cart.openMiniCart(); + await expect(page.locator(miniCartSelector.miniCartQuantitySelector)).toContainText(miniCartExpected.productQuantity); - }); + }); } -if(toggle.minicart.testMiniCartDeletion) { - test('Test minicart deletion', async ({ page }) => { - const cart = new Cart(page); - await cart.addSimpleProductToCart(slugs.simpleProductSlug); - await cart.openMiniCart(); - await page.click(miniCartSelector.miniCartDeleteProductButtonSelector); - - const successMessage = page.locator(globalSelector.successMessages, { hasText: miniCartExpected.productDeletedFromCartNotificationText }); - await expect(successMessage).toContainText(miniCartExpected.productDeletedFromCartNotificationText); - }); -} \ No newline at end of file +if (toggle.minicart.testMiniCartDeletion) { + test('Test minicart deletion', async ({page}) => { + const cart = new Cart(page); + await cart.addSimpleProductToCart(slugs.simpleProductSlug); + await cart.openMiniCart(); + await page.click(miniCartSelector.miniCartDeleteProductButtonSelector); + + const successMessage = page.locator(globalSelector.successMessages, {hasText: miniCartExpected.productDeletedFromCartNotificationText}); + await expect(successMessage).toContainText(miniCartExpected.productDeletedFromCartNotificationText); + }); +} diff --git a/tests/base/pages.spec.ts b/tests/base/pages.spec.ts index f72da49..76c8671 100644 --- a/tests/base/pages.spec.ts +++ b/tests/base/pages.spec.ts @@ -1,37 +1,37 @@ -import { test } from '@playwright/test'; +import {test} from '@playwright/test'; import slugs from './fixtures/before/slugs.json'; -import { PageTester } from './utils/PageTester'; +import {PageTester} from './utils/PageTester'; test.describe('Check for page errors', () => { - test('Check for homepage errors', async ({ page }) => { - const homepageTester = new PageTester(page, slugs.homepageSlug); - await homepageTester.testPage(); - }); - - test('Check for category page errors', async ({ page }) => { - const categoryTester = new PageTester(page, slugs.categorySlug); - await categoryTester.testPage(); - }); - - test('Check for product page errors', async ({ page }) => { - const productTester = new PageTester(page, slugs.pageSlug); - await productTester.testPage(); - }); - - test('Check for cart page errors', async ({ page }) => { - const cartTester = new PageTester(page, slugs.cartSlug); - await cartTester.testPage(); - }); - - test('Check for search page errors', async ({ page }) => { - const searchTester = new PageTester(page, slugs.searchSlug); - await searchTester.testPage(); - }); - - test('Check for contact page errors', async ({ page }) => { - const contactTester = new PageTester(page, slugs.contactSlug); - await contactTester.testPage(); - }); + test('Check for homepage errors', async ({page}) => { + const homepageTester = new PageTester(page, slugs.homepageSlug); + await homepageTester.testPage(); + }); + + test('Check for category page errors', async ({page}) => { + const categoryTester = new PageTester(page, slugs.categorySlug); + await categoryTester.testPage(); + }); + + test('Check for product page errors', async ({page}) => { + const productTester = new PageTester(page, slugs.pageSlug); + await productTester.testPage(); + }); + + test('Check for cart page errors', async ({page}) => { + const cartTester = new PageTester(page, slugs.cartSlug); + await cartTester.testPage(); + }); + + test('Check for search page errors', async ({page}) => { + const searchTester = new PageTester(page, slugs.searchSlug); + await searchTester.testPage(); + }); + + test('Check for contact page errors', async ({page}) => { + const contactTester = new PageTester(page, slugs.contactSlug); + await contactTester.testPage(); + }); }); diff --git a/tests/base/utils/Account.ts b/tests/base/utils/Account.ts index 8d095b0..09ca411 100644 --- a/tests/base/utils/Account.ts +++ b/tests/base/utils/Account.ts @@ -1,26 +1,26 @@ -import { expect, Page } from '@playwright/test'; +import {expect, Page} from '@playwright/test'; import slugs from '../fixtures/before/slugs.json'; import accountSelector from '../fixtures/during/selectors/account.json'; export class Account { - page: Page; + page: Page; - constructor(page: Page) { - this.page = page; - } + constructor(page: Page) { + this.page = page; + } - async login(email: string, password: string) { - await this.page.goto(slugs.loginSlug); + async login(email: string, password: string) { + await this.page.goto(slugs.loginSlug); - await this.page.fill(accountSelector.loginEmailAddressSelector, email); - await this.page.fill(accountSelector.loginPasswordSelector, password); + await this.page.fill(accountSelector.loginEmailAddressSelector, email); + await this.page.fill(accountSelector.loginPasswordSelector, password); - await this.page.click(accountSelector.loginButtonSelectorName); - await expect(this.page).toHaveURL(new RegExp(`${slugs.afterLoginSlug}.*`)); - } + await this.page.click(accountSelector.loginButtonSelectorName); + await expect(this.page).toHaveURL(new RegExp(`${slugs.afterLoginSlug}.*`)); + } - async logout() { - await this.page.locator(accountSelector.accountMenuItemsSelector).nth(accountSelector.logoutMenuItemPosition).click(); - await expect(this.page).toHaveURL(new RegExp(`${slugs.afterLogoutSlug}.*`)); - } + async logout() { + await this.page.locator(accountSelector.accountMenuItemsSelector).nth(accountSelector.logoutMenuItemPosition).click(); + await expect(this.page).toHaveURL(new RegExp(`${slugs.afterLogoutSlug}.*`)); + } } diff --git a/tests/base/utils/Browser.ts b/tests/base/utils/Browser.ts index b46b734..edee9f1 100644 --- a/tests/base/utils/Browser.ts +++ b/tests/base/utils/Browser.ts @@ -1,40 +1,41 @@ -import { Page } from '@playwright/test'; +import {Page} from '@playwright/test'; + export class Browser { - page: Page; - errors: string[] = []; + page: Page; + errors: string[] = []; - constructor(page: Page) { - this.page = page; - this.errors = []; - this._initializeListeners(); - } + constructor(page: Page) { + this.page = page; + this.errors = []; + this._initializeListeners(); + } - _initializeListeners() { - // Listen for console errors - this.page.on('console', (msg) => { - if (msg.type() === 'error') { - this.errors.push(`Console error: ${msg.text()}`); - } - if (msg.type() === 'warning') { - this.errors.push(`Console warning: ${msg.text()}`); - } - }); + _initializeListeners() { + // Listen for console errors + this.page.on('console', (msg) => { + if (msg.type() === 'error') { + this.errors.push(`Console error: ${msg.text()}`); + } + if (msg.type() === 'warning') { + this.errors.push(`Console warning: ${msg.text()}`); + } + }); - // Listen for page errors (uncaught exceptions, etc.) - this.page.on('pageerror', (exception) => { - this.errors.push(`Page error: ${exception.message}`); - }); + // Listen for page errors (uncaught exceptions, etc.) + this.page.on('pageerror', (exception) => { + this.errors.push(`Page error: ${exception.message}`); + }); - // Listen for failed requests - this.page.on('requestfailed', (request) => { - const failure = request.failure(); - if (failure) { - this.errors.push(`Request failed: ${request.url()} - ${failure.errorText}`); - } - }); - } + // Listen for failed requests + this.page.on('requestfailed', (request) => { + const failure = request.failure(); + if (failure) { + this.errors.push(`Request failed: ${request.url()} - ${failure.errorText}`); + } + }); + } - getErrors() { - return this.errors; - } + getErrors() { + return this.errors; + } } diff --git a/tests/base/utils/Cart.ts b/tests/base/utils/Cart.ts index ff49585..8b7f328 100644 --- a/tests/base/utils/Cart.ts +++ b/tests/base/utils/Cart.ts @@ -1,26 +1,27 @@ -import { expect, Page } from '@playwright/test'; +import {expect, Page} from '@playwright/test'; import slugs from '../fixtures/before/slugs.json'; -import productPageSelector from '../fixtures/during/selectors/product-page.json'; +import productPageSelector + from '../fixtures/during/selectors/product-page.json'; import productPageExpected from '../fixtures/verify/expects/product-page.json'; import miniCartSelector from '../fixtures/during/selectors/minicart.json'; export class Cart { - page: Page; + page: Page; - constructor(page: Page) { - this.page = page; - } + constructor(page: Page) { + this.page = page; + } - async addSimpleProductToCart(productSlug: string) { - await this.page.goto(slugs.simpleProductSlug); - await this.page.click(productPageSelector.addToCartButtonSelector); - await expect(this.page.locator(`text=${productPageExpected.productAddedToCartNotificationText}`)).toBeVisible(); - } + async addSimpleProductToCart(productSlug: string) { + await this.page.goto(slugs.simpleProductSlug); + await this.page.click(productPageSelector.addToCartButtonSelector); + await expect(this.page.locator(`text=${productPageExpected.productAddedToCartNotificationText}`)).toBeVisible(); + } - async openMiniCart() { - await this.page.click(miniCartSelector.miniCartIconSelector); - await expect(this.page.locator(miniCartSelector.miniCartDrawerTitleSelector)).toBeVisible(); - } + async openMiniCart() { + await this.page.click(miniCartSelector.miniCartIconSelector); + await expect(this.page.locator(miniCartSelector.miniCartDrawerTitleSelector)).toBeVisible(); + } } diff --git a/tests/base/utils/Checkout.ts b/tests/base/utils/Checkout.ts index 94fec00..db9f2ca 100644 --- a/tests/base/utils/Checkout.ts +++ b/tests/base/utils/Checkout.ts @@ -1,9 +1,9 @@ -import { Page } from '@playwright/test'; +import {Page} from '@playwright/test'; export class Checkout { - page: Page; + page: Page; - constructor(page: Page) { - this.page = page - } -} \ No newline at end of file + constructor(page: Page) { + this.page = page + } +} diff --git a/tests/base/utils/Contact.ts b/tests/base/utils/Contact.ts index 47cf658..9ecf715 100644 --- a/tests/base/utils/Contact.ts +++ b/tests/base/utils/Contact.ts @@ -1,15 +1,15 @@ -import { expect, Page } from '@playwright/test'; +import {expect, Page} from '@playwright/test'; export class Contact { - page: Page; - url: string; + page: Page; + url: string; - constructor(page: Page) { - this.page = page; - } - - async navigateAndCheckForm() { - const response = await this.page.goto(this.url); - expect(response?.status()).toBe(200); - } + constructor(page: Page) { + this.page = page; + } + + async navigateAndCheckForm() { + const response = await this.page.goto(this.url); + expect(response?.status()).toBe(200); + } } diff --git a/tests/base/utils/PageTester.ts b/tests/base/utils/PageTester.ts index 3feac7c..36a3d86 100644 --- a/tests/base/utils/PageTester.ts +++ b/tests/base/utils/PageTester.ts @@ -1,57 +1,57 @@ -import { expect, Page } from '@playwright/test'; -import { Browser } from './Browser'; +import {expect, Page} from '@playwright/test'; +import {Browser} from './Browser'; import globalExpect from '../fixtures/verify/expects/global.json'; import flags from '../config/test-toggles.json'; export class PageTester { - page: Page; - url: string; - errorHandler: Browser; - errors: Object[]; + page: Page; + url: string; + errorHandler: Browser; + errors: Object[]; - constructor(page: Page, url: string) { - this.page = page; - this.url = url; - this.errorHandler = new Browser(page); - this.errors = []; - } - - async navigateAndCheckStatus() { - const response = await this.page.goto(this.url); - expect(response?.status()).toBe(200); - } + constructor(page: Page, url: string) { + this.page = page; + this.url = url; + this.errorHandler = new Browser(page); + this.errors = []; + } - async waitAndCheckForErrors(timeout = 2000) { - await this.page.waitForTimeout(timeout); - await this.captureConsoleErrors(); - const errors = this.errorHandler.getErrors(); - this.errors = this.errors.concat(errors); - expect(this.errors).toHaveLength(0); - } + async navigateAndCheckStatus() { + const response = await this.page.goto(this.url); + expect(response?.status()).toBe(200); + } - async captureConsoleErrors() { - this.page.on('console', (msg) => { - if (msg.type() === 'error' || msg.type() === 'warning') { - this.errors.push({ - message: msg.text(), - location: msg.location(), - type: msg.type() - }); - } + async waitAndCheckForErrors(timeout = 2000) { + await this.page.waitForTimeout(timeout); + await this.captureConsoleErrors(); + const errors = this.errorHandler.getErrors(); + this.errors = this.errors.concat(errors); + expect(this.errors).toHaveLength(0); + } + + async captureConsoleErrors() { + this.page.on('console', (msg) => { + if (msg.type() === 'error' || msg.type() === 'warning') { + this.errors.push({ + message: msg.text(), + location: msg.location(), + type: msg.type() }); - } + } + }); + } - async measurePerformance() { - const timing = JSON.parse(await this.page.evaluate(() => JSON.stringify(window.performance.timing))); - const loadTime = timing.loadEventEnd - timing.navigationStart; - expect(loadTime).toBeLessThan(globalExpect.maxPageLoadTimeInMs); - } + async measurePerformance() { + const timing = JSON.parse(await this.page.evaluate(() => JSON.stringify(window.performance.timing))); + const loadTime = timing.loadEventEnd - timing.navigationStart; + expect(loadTime).toBeLessThan(globalExpect.maxPageLoadTimeInMs); + } - async testPage() { - if (flags.testForPageErrors) { - await this.navigateAndCheckStatus(); - await this.waitAndCheckForErrors(); - await this.measurePerformance(); - } + async testPage() { + if (flags.testForPageErrors) { + await this.navigateAndCheckStatus(); + await this.waitAndCheckForErrors(); + await this.measurePerformance(); } + } }