Skip to content

Commit

Permalink
page objects refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
StalinDurjo committed Jan 7, 2025
1 parent 09f5490 commit 4b1662c
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 175 deletions.
16 changes: 6 additions & 10 deletions tests/pw/pages/frontend/cart.page.ts
Original file line number Diff line number Diff line change
@@ -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"]');
}
Expand All @@ -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();
}
}
18 changes: 3 additions & 15 deletions tests/pw/pages/frontend/my-account/auth/my-account-auth.page.ts
Original file line number Diff line number Diff line change
@@ -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();
}
}
6 changes: 1 addition & 5 deletions tests/pw/pages/frontend/my-orders/all-my-orders.page.ts
Original file line number Diff line number Diff line change
@@ -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();
}
}
12 changes: 2 additions & 10 deletions tests/pw/pages/frontend/my-orders/customer-order-details.page.ts
Original file line number Diff line number Diff line change
@@ -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();
}
}
6 changes: 1 addition & 5 deletions tests/pw/pages/frontend/navigation/main-menu.page.ts
Original file line number Diff line number Diff line change
@@ -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();
}
}
6 changes: 1 addition & 5 deletions tests/pw/pages/frontend/shop/shop.page.ts
Original file line number Diff line number Diff line change
@@ -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();
}
}
12 changes: 2 additions & 10 deletions tests/pw/pages/frontend/shop/single-product.page.ts
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
18 changes: 3 additions & 15 deletions tests/pw/pages/wp-admin/dokan/settings/modules.page.ts
Original file line number Diff line number Diff line change
@@ -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();
}
}
24 changes: 4 additions & 20 deletions tests/pw/pages/wp-admin/dokan/settings/shipping-status.page.ts
Original file line number Diff line number Diff line change
@@ -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();

Expand 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();
}
}
6 changes: 1 addition & 5 deletions tests/pw/pages/wp-admin/products/all-products.page.ts
Original file line number Diff line number Diff line change
@@ -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();
}
}
6 changes: 1 addition & 5 deletions tests/pw/pages/wp-admin/products/edit-product.page.ts
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit 4b1662c

Please sign in to comment.