From 4b1662c64ec46b41fb92b280fdd2a1afb4bd692c Mon Sep 17 00:00:00 2001 From: Stalin <34745567+StalinDurjo@users.noreply.github.com> Date: Wed, 8 Jan 2025 00:10:11 +0600 Subject: [PATCH] page objects refactored --- tests/pw/pages/frontend/cart.page.ts | 16 +++---- .../my-account/auth/my-account-auth.page.ts | 18 ++------ .../frontend/my-orders/all-my-orders.page.ts | 6 +-- .../my-orders/customer-order-details.page.ts | 12 +----- .../frontend/navigation/main-menu.page.ts | 6 +-- tests/pw/pages/frontend/shop/shop.page.ts | 6 +-- .../frontend/shop/single-product.page.ts | 12 +----- .../orders/vendor-edit-order.page.ts | 42 ++++--------------- .../products/product-add-edit.page.ts | 24 ++--------- .../settings/store/vendor-store.page.ts | 18 ++------ .../wp-admin/dokan/settings/modules.page.ts | 18 ++------ .../dokan/settings/shipping-status.page.ts | 24 ++--------- .../wp-admin/products/all-products.page.ts | 6 +-- .../wp-admin/products/edit-product.page.ts | 6 +-- 14 files changed, 39 insertions(+), 175 deletions(-) diff --git a/tests/pw/pages/frontend/cart.page.ts b/tests/pw/pages/frontend/cart.page.ts index 02cb9ceba4..6ffb84491d 100644 --- a/tests/pw/pages/frontend/cart.page.ts +++ b/tests/pw/pages/frontend/cart.page.ts @@ -1,14 +1,6 @@ import { BasePage } from '@pages/basePage'; export default class CartPage extends BasePage { - quantityInputFieldFor(productTitle: string) { - return this.page.locator(`//div[@class="quantity"]/label[contains(text(), "${productTitle}")]/following-sibling::input`); - } - - updateCartButton() { - return this.page.locator('//button[@name="update_cart"]'); - } - quantityErrorElement() { return this.page.locator('//td[@class="product-quantity"]/div[@class="required"]'); } @@ -18,10 +10,14 @@ export default class CartPage extends BasePage { } async enterQuantityValue(productTitle: string, quantityValue: string) { - await this.quantityInputFieldFor(productTitle).fill(quantityValue); + await this.page.locator(`//div[@class="quantity"]/label[contains(text(), "${productTitle}")]/following-sibling::input`).fill(quantityValue); } async clickOnUpdateCartButton() { - await this.updateCartButton().click(); + await this.page.locator('//button[@name="update_cart"]').click(); + } + + async removeProductByName(productName: string) { + await this.page.locator(`//div[@class="quantity"]/label[contains(text(), "${productName}")]/../../../td[1]/a`).click(); } } diff --git a/tests/pw/pages/frontend/my-account/auth/my-account-auth.page.ts b/tests/pw/pages/frontend/my-account/auth/my-account-auth.page.ts index bbfbdc9e3a..071cf1f1b7 100644 --- a/tests/pw/pages/frontend/my-account/auth/my-account-auth.page.ts +++ b/tests/pw/pages/frontend/my-account/auth/my-account-auth.page.ts @@ -1,27 +1,15 @@ import { BasePage } from '@pages/basePage'; export default class MyAccountAuthPage extends BasePage { - usernameInputField() { - return this.page.locator('#username'); - } - - passwordInputField() { - return this.page.locator('#password'); - } - - loginButton() { - return this.page.locator('//button[@name="login"]'); - } - async enterUsername(username: string) { - await this.usernameInputField().fill(username); + await this.page.locator('#username').fill(username); } async enterPassword(password: string) { - await this.passwordInputField().fill(password); + await this.page.locator('#password').fill(password); } async clickOnLoginButton() { - await this.loginButton().click(); + await this.page.locator('//button[@name="login"]').click(); } } diff --git a/tests/pw/pages/frontend/my-orders/all-my-orders.page.ts b/tests/pw/pages/frontend/my-orders/all-my-orders.page.ts index bea7e1eb9e..981026719f 100644 --- a/tests/pw/pages/frontend/my-orders/all-my-orders.page.ts +++ b/tests/pw/pages/frontend/my-orders/all-my-orders.page.ts @@ -1,11 +1,7 @@ import { BasePage } from '@pages/basePage'; export default class AllMyOrdersPage extends BasePage { - viewButtonByOrderId(orderId: string) { - return this.page.locator(`//td[@class="order-number"]/a[contains(text(), "${orderId}")]/../following-sibling::td[5]/a`); - } - async clickOnViewButtonByOrderId(orderId: string) { - await this.viewButtonByOrderId(orderId).click(); + await this.page.locator(`//td[@class="order-number"]/a[contains(text(), "${orderId}")]/../following-sibling::td[5]/a`).click(); } } diff --git a/tests/pw/pages/frontend/my-orders/customer-order-details.page.ts b/tests/pw/pages/frontend/my-orders/customer-order-details.page.ts index fa679188bd..5a03fc5ac7 100644 --- a/tests/pw/pages/frontend/my-orders/customer-order-details.page.ts +++ b/tests/pw/pages/frontend/my-orders/customer-order-details.page.ts @@ -1,23 +1,15 @@ import { BasePage } from '@pages/basePage'; export default class CustomerOrderDetailsPage extends BasePage { - orderReceivedButtonByShipmentNumber(shipmentNumber: string) { - return this.page.locator(`//h4[@class="shippments-tracking-title"]/strong[text()="Shipment ${shipmentNumber} "]/../../div[1]/strong[@class="customer-status"]`); - } - trackingStatusByShipmentNumber(shipmentNumber: string) { return this.page.locator(`//h4[@class="shippments-tracking-title"]/strong[text()="Shipment ${shipmentNumber} "]/../../div[1]/p/strong`); } - dialogueBoxOkButton() { - return this.page.locator('//div[@role="dialog"]/div[6]/button[text()="OK"]'); - } - async markOrderAsReceived(shipmentNumber: string) { - await this.orderReceivedButtonByShipmentNumber(shipmentNumber).click(); + await this.page.locator(`//h4[@class="shippments-tracking-title"]/strong[text()="Shipment ${shipmentNumber} "]/../../div[1]/strong[@class="customer-status"]`).click(); } async clickOnDialogBoxOkButton() { - await this.dialogueBoxOkButton().click(); + await this.page.locator('//div[@role="dialog"]/div[6]/button[text()="OK"]').click(); } } diff --git a/tests/pw/pages/frontend/navigation/main-menu.page.ts b/tests/pw/pages/frontend/navigation/main-menu.page.ts index 491727a748..ef9c2f5bb4 100644 --- a/tests/pw/pages/frontend/navigation/main-menu.page.ts +++ b/tests/pw/pages/frontend/navigation/main-menu.page.ts @@ -1,11 +1,7 @@ import { BasePage } from '@pages/basePage'; export default class StorefrontMainMenu extends BasePage { - cartContentLink() { - return this.page.locator('.cart-contents'); - } - async clickOnCartContentLink() { - await this.cartContentLink().click(); + await this.page.locator('.cart-contents').click(); } } diff --git a/tests/pw/pages/frontend/shop/shop.page.ts b/tests/pw/pages/frontend/shop/shop.page.ts index 54e5ba10f1..a76fb4fa90 100644 --- a/tests/pw/pages/frontend/shop/shop.page.ts +++ b/tests/pw/pages/frontend/shop/shop.page.ts @@ -1,11 +1,7 @@ import { BasePage } from '@pages/basePage'; export default class ShopPage extends BasePage { - productTitle() { - return this.page.locator('.woocommerce-loop-product__title'); - } - async clickOnProductWithTitle(productTitle: string) { - await this.productTitle().getByText(productTitle).click(); + await this.page.locator('.woocommerce-loop-product__title').getByText(productTitle).click(); } } diff --git a/tests/pw/pages/frontend/shop/single-product.page.ts b/tests/pw/pages/frontend/shop/single-product.page.ts index 24cb13078a..de688d2ba3 100644 --- a/tests/pw/pages/frontend/shop/single-product.page.ts +++ b/tests/pw/pages/frontend/shop/single-product.page.ts @@ -1,23 +1,15 @@ import { BasePage } from '@pages/basePage'; export default class SingleProductPage extends BasePage { - quantityInputFieldFor(productTitle: string) { - return this.page.locator(`//div[@class="quantity"]/label[contains(text(), "${productTitle}")]/following-sibling::input`); - } - - addToCartButton() { - return this.page.locator('.single_add_to_cart_button'); - } - errorMessageElement() { return this.page.locator('//ul[@class="woocommerce-error"]/li'); } async enterQuantityValue(productTitle: string, quantityValue: string) { - await this.quantityInputFieldFor(productTitle).fill(quantityValue); + await this.page.locator(`//div[@class="quantity"]/label[contains(text(), "${productTitle}")]/following-sibling::input`).fill(quantityValue); } async clickOnAddToCartButton() { - await this.addToCartButton().click(); + await this.page.locator('.single_add_to_cart_button').click(); } } diff --git a/tests/pw/pages/frontend/vendor-dashboard/orders/vendor-edit-order.page.ts b/tests/pw/pages/frontend/vendor-dashboard/orders/vendor-edit-order.page.ts index 901a7ffb1a..c45fb59b73 100644 --- a/tests/pw/pages/frontend/vendor-dashboard/orders/vendor-edit-order.page.ts +++ b/tests/pw/pages/frontend/vendor-dashboard/orders/vendor-edit-order.page.ts @@ -1,59 +1,31 @@ import { BasePage } from '@pages/basePage'; export default class VendorEditOrderPage extends BasePage { - createNewShipmentButton() { - return this.page.locator('#create-tracking-status-action'); - } - - shipmentItemCheckboxByIndex(itemNumber: string) { - return this.page.locator(`//form[@id="add-shipping-tracking-status-form"]/div/table/tbody[@id="order_line_items"]/tr[${itemNumber}]/td[1]/label/input`); - } - - shippingStatusDropdown() { - return this.page.locator('#shipment-status'); - } - - shippingProviderDropdown() { - return this.page.locator('#shipping_status_provider'); - } - - shippingDateField() { - return this.page.locator('#shipped_status_date'); - } - - shippingTrackingNumberField() { - return this.page.locator('#tracking_status_number'); - } - - createShipmentButton() { - return this.page.locator('#add-tracking-status-details'); - } - async clickOnCreateNewShipmentButton() { - await this.createNewShipmentButton().click(); + await this.page.locator('#create-tracking-status-action').click(); } async clickOnShipmentItemCheckboxByIndex(itemNumber: string) { - await this.shipmentItemCheckboxByIndex(itemNumber).click(); + await this.page.locator(`//form[@id="add-shipping-tracking-status-form"]/div/table/tbody[@id="order_line_items"]/tr[${itemNumber}]/td[1]/label/input`).click(); } async selectShippingStatus(status: string) { - await this.shippingStatusDropdown().selectOption(status); + await this.page.locator('#shipment-status').selectOption(status); } async selectShippingProvider(providerName: string) { - await this.shippingProviderDropdown().selectOption(providerName); + await this.page.locator('#shipping_status_provider').selectOption(providerName); } async enterShippingDate(date: string) { - await this.shippingDateField().fill(date); + await this.page.locator('#shipped_status_date').fill(date); } async enterShippingTrackingNumber(trackingNumber: string) { - await this.shippingTrackingNumberField().fill(trackingNumber); + await this.page.locator('#tracking_status_number').fill(trackingNumber); } async clickOnCreateShipmentButton() { - await this.createShipmentButton().click(); + await this.page.locator('#add-tracking-status-details').click(); } } diff --git a/tests/pw/pages/frontend/vendor-dashboard/products/product-add-edit.page.ts b/tests/pw/pages/frontend/vendor-dashboard/products/product-add-edit.page.ts index 3c152817ae..52c0913dc8 100644 --- a/tests/pw/pages/frontend/vendor-dashboard/products/product-add-edit.page.ts +++ b/tests/pw/pages/frontend/vendor-dashboard/products/product-add-edit.page.ts @@ -1,35 +1,19 @@ import { BasePage } from '@pages/basePage'; export default class VendorProductAddEditPage extends BasePage { - simpleProductMinQtyInputField() { - return this.page.locator('#dokan_simple_product_min_quantity'); - } - - simpleProductMaxQtyInputField() { - return this.page.locator('#dokan_simple_product_max_quantity'); - } - - productStatusSelectField() { - return this.page.locator('#post_status'); - } - - saveProductButton() { - return this.page.locator('#publish'); - } - async enterSimpleProductMinQty(quantity: string) { - await this.simpleProductMinQtyInputField().fill(quantity); + await this.page.locator('#min_quantity').fill(quantity); } async enterSimpleProductMaxQty(quantity: string) { - await this.simpleProductMaxQtyInputField().fill(quantity); + await this.page.locator('#max_quantity').fill(quantity); } async selectProductStatus(status: 'publish' | 'draft' | 'pending') { - await this.productStatusSelectField().selectOption(status); + await this.page.locator('#post_status').selectOption(status); } async clickOnSaveProduct() { - await this.saveProductButton().click(); + await this.page.locator('#publish').click(); } } diff --git a/tests/pw/pages/frontend/vendor-dashboard/settings/store/vendor-store.page.ts b/tests/pw/pages/frontend/vendor-dashboard/settings/store/vendor-store.page.ts index d1b29313f4..f66c269864 100644 --- a/tests/pw/pages/frontend/vendor-dashboard/settings/store/vendor-store.page.ts +++ b/tests/pw/pages/frontend/vendor-dashboard/settings/store/vendor-store.page.ts @@ -1,27 +1,15 @@ import { BasePage } from '@pages/basePage'; export default class VendorStoreSettingsPage extends BasePage { - minimumOrderAmountInputField() { - return this.page.locator('#min_amount_to_order'); - } - - maximumOrderAmountInputField() { - return this.page.locator('#max_amount_to_order'); - } - - updateSettingsButton() { - return this.page.locator(`//input[@name="dokan_update_store_settings"]`); - } - async enterMinimumOrderAmount(amount: string) { - await this.minimumOrderAmountInputField().fill(amount); + await this.page.locator('#min_amount_to_order').fill(amount); } async enterMaximumOrderAmount(amount: string) { - await this.maximumOrderAmountInputField().fill(amount); + await this.page.locator('#max_amount_to_order').fill(amount); } async clickOnUpdateSettingsButton() { - await this.updateSettingsButton().click(); + await this.page.locator(`//input[@name="dokan_update_store_settings"]`).click(); } } diff --git a/tests/pw/pages/wp-admin/dokan/settings/modules.page.ts b/tests/pw/pages/wp-admin/dokan/settings/modules.page.ts index 2ad30a4c50..ae8acf1915 100644 --- a/tests/pw/pages/wp-admin/dokan/settings/modules.page.ts +++ b/tests/pw/pages/wp-admin/dokan/settings/modules.page.ts @@ -1,31 +1,19 @@ import { BasePage } from '@pages/basePage'; export default class DokanModulesPage extends BasePage { - searchInputField() { - return this.page.locator('//div[@class="search-box"]/input'); - } - moduleTitle() { return this.page.locator(`//div[@class="module-details"]/h3/a`); } - moduleToggleField(moduleName: string) { - return this.page.locator(`//div[@class="module-details"]/h3/a[contains(text(), "${moduleName}")]/../../following-sibling::div/div[2]/label`); - } - - activeModuleTab() { - return this.page.locator(`//div[@class="module-filter-left"]/ul/li[2]/a`); - } - async searchFor(searchTerm: string) { - await this.searchInputField().fill(searchTerm); + await this.page.locator('//div[@class="search-box"]/input').fill(searchTerm); } async clickOnModuleToggleButton(moduleName: string) { - await this.moduleToggleField(moduleName).click(); + await this.page.locator(`//div[@class="module-details"]/h3/a[contains(text(), "${moduleName}")]/../../following-sibling::div/div[2]/label`).click(); } async clickOnActiveModulesTab() { - await this.activeModuleTab().click(); + await this.page.locator(`//div[@class="module-filter-left"]/ul/li[2]/a`).click(); } } diff --git a/tests/pw/pages/wp-admin/dokan/settings/shipping-status.page.ts b/tests/pw/pages/wp-admin/dokan/settings/shipping-status.page.ts index f8a3f66329..7c778d46f0 100644 --- a/tests/pw/pages/wp-admin/dokan/settings/shipping-status.page.ts +++ b/tests/pw/pages/wp-admin/dokan/settings/shipping-status.page.ts @@ -1,18 +1,6 @@ import { BasePage } from '@pages/basePage'; export default class DokanShippingStatusPage extends BasePage { - shippingStatusTab() { - return this.page.locator('//div[@class="nav-title"][text()="Shipping Status"]'); - } - - allowShipmentTrackingCheckbox() { - return this.page.locator('(//p/../following-sibling::div/label/label)[1]'); - } - - allowMarkAsReceivedCheckbox() { - return this.page.locator('(//p/../following-sibling::div/label/label)[2]'); - } - async shippingStatusItem(status: string) { const list = this.page.locator('//ul[@class="dokan-settings-repeatable-list"]/li').all(); @@ -27,23 +15,19 @@ export default class DokanShippingStatusPage extends BasePage { return locator; } - saveChangesButton() { - return this.page.locator('#submit'); - } - async clickOnShippingStatusTab() { - await this.shippingStatusTab().click(); + await this.page.locator('//div[@class="nav-title"][text()="Shipping Status"]').click(); } async clickOnAllowShipmentTrackingCheckbox() { - await this.allowShipmentTrackingCheckbox().click(); + await this.page.locator('(//p/../following-sibling::div/label/label)[1]').click(); } async clickOnAllowMarkAsReceivedCheckbox() { - await this.allowMarkAsReceivedCheckbox().click(); + await this.page.locator('(//p/../following-sibling::div/label/label)[2]').click(); } async clickOnSaveChangesButton() { - await this.saveChangesButton().click(); + await this.page.locator('#submit').click(); } } diff --git a/tests/pw/pages/wp-admin/products/all-products.page.ts b/tests/pw/pages/wp-admin/products/all-products.page.ts index fb1f08618c..444882dea4 100644 --- a/tests/pw/pages/wp-admin/products/all-products.page.ts +++ b/tests/pw/pages/wp-admin/products/all-products.page.ts @@ -1,11 +1,7 @@ import { BasePage } from '@pages/basePage'; export default class AllProductsPage extends BasePage { - productTitleById(productId: string) { - return this.page.locator(`//tr[@id="post-${productId}"]/td[2]/strong/a`); - } - async clickOnProductTitleById(productId: string) { - await this.productTitleById(productId).click(); + await this.page.locator(`//tr[@id="post-${productId}"]/td[2]/strong/a`).click(); } } diff --git a/tests/pw/pages/wp-admin/products/edit-product.page.ts b/tests/pw/pages/wp-admin/products/edit-product.page.ts index 9914bccda3..59f8bdadde 100644 --- a/tests/pw/pages/wp-admin/products/edit-product.page.ts +++ b/tests/pw/pages/wp-admin/products/edit-product.page.ts @@ -1,11 +1,7 @@ import { BasePage } from '@pages/basePage'; export default class EditProductPage extends BasePage { - publishButton() { - return this.page.locator('#publish'); - } - async clickOnPublishButton() { - await this.publishButton().click(); + await this.page.locator('#publish').click(); } }