From 757c06586aa916b0a0f7e0f4d40a5ad12cbdd308 Mon Sep 17 00:00:00 2001 From: Shay Date: Wed, 29 Oct 2025 12:03:38 +0100 Subject: [PATCH 1/2] Moved selectors to element-identifiers.json --- tests/config/element-identifiers.json | 8 +++++++- tests/poms/frontend/checkout.page.ts | 14 +++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/tests/config/element-identifiers.json b/tests/config/element-identifiers.json index ca4bfc4..4e699b4 100644 --- a/tests/config/element-identifiers.json +++ b/tests/config/element-identifiers.json @@ -118,7 +118,9 @@ "remove": "Remove", "shippingAddressRadioLocator": "#shipping-details input[type='radio']", "shippingMethodFixedLabel": "Fixed", - "shippingMethodTableRateLabel": "Table Rate" + "shippingMethodTableRateLabel": "Table Rate", + "shippingPriceText": "Shipping & Handling (Flat Rate - Fixed)", + "taxPriceText": "Tax" }, "comparePage": { "removeCompareLabel": "Remove Product", @@ -156,6 +158,10 @@ "customerOverviewPage": { "tableSearchFieldLabel": "Search by keyword" }, + "financial" : { + "subTotal": "Subtotal", + "grandTotal": "Grand Total" + }, "footerPage": { "footerLocator": ".page-footer", "currencyIdentifier": "#currency-heading", diff --git a/tests/poms/frontend/checkout.page.ts b/tests/poms/frontend/checkout.page.ts index bfcdf90..266a7c7 100644 --- a/tests/poms/frontend/checkout.page.ts +++ b/tests/poms/frontend/checkout.page.ts @@ -34,10 +34,14 @@ class CheckoutPage extends MagewireUtils { this.showDiscountFormButton = this.page.getByRole('button', {name: UIReference.checkout.openDiscountFormLabel}); this.placeOrderButton = this.page.getByRole('button', { name: UIReference.checkout.placeOrderButtonLabel }); this.continueShoppingButton = this.page.getByRole('link', { name: UIReference.checkout.continueShoppingLabel }); - this.subtotalElement = page.getByText('Subtotal $'); - this.shippingElement = page.getByText('Shipping & Handling (Flat Rate - Fixed) $'); - this.taxElement = page.getByText('Tax $'); - this.grandTotalElement = page.getByText('Grand Total $'); + // this.subtotalElement = page.getByText('Subtotal $'); + this.subtotalElement = page.getByText(`${UIReference.financial.subTotal} ${UIReference.general.genericPriceSymbol}`); + // this.shippingElement = page.getByText('Shipping & Handling (Flat Rate - Fixed) $'); + this.shippingElement = page.getByText(`${UIReference.checkout.shippingPriceText} ${UIReference.general.genericPriceSymbol}`); + // this.taxElement = page.getByText('Tax $'); + this.taxElement = page.getByText(`${UIReference.checkout.taxPriceText} ${UIReference.general.genericPriceSymbol}`); + // this.grandTotalElement = page.getByText('Grand Total $'); + this.grandTotalElement = page.getByText(`${UIReference.financial.grandTotal} ${UIReference.general.genericPriceSymbol}`); this.paymentMethodOptionCreditCard = this.page.getByLabel(UIReference.checkout.paymentOptionCreditCardLabel); this.paymentMethodOptionPaypal = this.page.getByLabel(UIReference.checkout.paymentOptionPaypalLabel); this.creditCardNumberField = this.page.getByLabel(UIReference.checkout.creditCardNumberLabel); @@ -218,7 +222,7 @@ class CheckoutPage extends MagewireUtils { // await this.page.getByLabel('Country').selectOption('US'); const country = faker.helpers.arrayElement(inputValues.addressCountries); const countrySelectorField = this.page.getByLabel(UIReference.newAddress.countryLabel); - const stateInputField = this.page.getByRole('textbox', { name: 'State/Province' }); + const stateInputField = this.page.getByRole('textbox', { name: UIReference.newAddress.provinceSelectLabel }); const stateSelectorField = stateInputField.filter({ hasText: UIReference.newAddress.provinceSelectFilterLabel }); From e27b5158970d36ffe82065069943a46fe85d6e9a Mon Sep 17 00:00:00 2001 From: Shay Date: Wed, 29 Oct 2025 12:15:10 +0100 Subject: [PATCH 2/2] Moved more selectors to element-identifiers, added expect message to mainmenu.page --- tests/config/element-identifiers.json | 2 ++ tests/poms/frontend/contact.page.ts | 4 ++-- tests/poms/frontend/mainmenu.page.ts | 8 ++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/config/element-identifiers.json b/tests/config/element-identifiers.json index 4e699b4..d54f3b3 100644 --- a/tests/config/element-identifiers.json +++ b/tests/config/element-identifiers.json @@ -180,6 +180,7 @@ "genericPriceSymbol": "$", "genericSaveButtonLabel": "Save", "genericSubmitButtonLabel": "Submit", + "headerLocator": "#header", "loadingSpinnerLocator": "#container .spinner", "messageLocator": "div.message", "removeLabel": "Remove", @@ -222,6 +223,7 @@ "wishListButtonLabel" : "My Wish List" }, "miniCart": { + "cartDrawerLocator": "#cart-drawer-title", "checkOutButtonLabel": "Checkout", "editProductIconLabel": "Edit product", "minicartButtonLocator": "#menu-cart-icon", diff --git a/tests/poms/frontend/contact.page.ts b/tests/poms/frontend/contact.page.ts index 74b6d0c..a34fcfa 100644 --- a/tests/poms/frontend/contact.page.ts +++ b/tests/poms/frontend/contact.page.ts @@ -14,7 +14,7 @@ class ContactPage { constructor(page: Page){ this.page = page; this.nameField = this.page.getByLabel(UIReference.credentials.nameFieldLabel); - this.emailField = this.page.getByPlaceholder('Email', { exact: true }); + this.emailField = this.page.getByPlaceholder(UIReference.credentials.emailFieldLabel, { exact: true }); this.messageField = this.page.locator(UIReference.contactPage.messageFieldSelector); this.sendFormButton = this.page.getByRole('button', { name: UIReference.general.genericSubmitButtonLabel }); } @@ -39,4 +39,4 @@ class ContactPage { } } -export default ContactPage; \ No newline at end of file +export default ContactPage; diff --git a/tests/poms/frontend/mainmenu.page.ts b/tests/poms/frontend/mainmenu.page.ts index 29504a7..649a685 100644 --- a/tests/poms/frontend/mainmenu.page.ts +++ b/tests/poms/frontend/mainmenu.page.ts @@ -20,7 +20,7 @@ class MainMenuPage { constructor(page: Page) { this.page = page; - this.mainMenuElement = page.locator('#header'); + this.mainMenuElement = page.locator(UIReference.general.headerLocator); this.mainMenuAccountButton = this.mainMenuElement.getByRole('button', { name: UIReference.mainMenu.myAccountButtonLabel }); this.mainMenuMiniCartButton = this.mainMenuElement.getByLabel(UIReference.mainMenu.miniCartLabel); this.mainMenuMyAccountItem = this.mainMenuElement.getByTitle(UIReference.mainMenu.myAccountButtonLabel); @@ -165,7 +165,7 @@ class MainMenuPage { // By adding 'force', we can bypass the 'aria-disabled' tag. await this.mainMenuMiniCartButton.click({force: true}); - let miniCartDrawer = this.page.locator("#cart-drawer-title"); + let miniCartDrawer = this.page.locator(UIReference.miniCart.cartDrawerLocator); await expect(miniCartDrawer.getByText(outcomeMarker.miniCart.miniCartTitle)).toBeVisible(); } @@ -199,8 +199,8 @@ class MainMenuPage { await this.mainMenuLogoutItem.click(); //assertions: notification that user is logged out & logout button no longer visible - await expect(this.page.getByText(outcomeMarker.logout.logoutConfirmationText, { exact: true })).toBeVisible(); - await expect(this.mainMenuLogoutItem).toBeHidden(); + await expect(this.page.getByText(outcomeMarker.logout.logoutConfirmationText, { exact: true }), "Message shown that confirms you're logged out").toBeVisible(); + await expect(this.mainMenuLogoutItem, `Log out button is no longer visible`).toBeHidden(); } }