From 242edc6aa057030afcf35bd99e3b3d063729cb32 Mon Sep 17 00:00:00 2001 From: Stalin Date: Thu, 12 Sep 2024 15:23:17 +0600 Subject: [PATCH 01/10] page objects for min-max added --- .../my-account/auth/my-account-auth.page.ts | 32 ++++++++++ .../frontend/my-orders/all-my-orders.page.ts | 16 +++++ .../my-orders/customer-order-details.page.ts | 28 ++++++++ tests/pw/pages/frontend/shop/shop.page.ts | 16 +++++ .../frontend/shop/single-product.page.ts | 20 ++++++ .../common/vendor-sidebar.page.ts | 25 ++++++++ .../orders/vendor-all-orders.page.ts | 16 +++++ .../orders/vendor-edit-order.page.ts | 64 +++++++++++++++++++ .../products/product-add-edit.page.ts | 40 ++++++++++++ .../products/products-list.page.ts | 16 +++++ .../settings/store/vendor-store.page.ts | 28 ++++++++ .../pw/pages/wp-admin/common/sidebar.page.ts | 20 ++++++ .../wp-admin/dokan/settings/modules.page.ts | 36 +++++++++++ .../dokan/settings/shipping-status.page.ts | 54 ++++++++++++++++ .../wp-admin/products/all-products.page.ts | 16 +++++ .../wp-admin/products/edit-product.page.ts | 16 +++++ 16 files changed, 443 insertions(+) create mode 100644 tests/pw/pages/frontend/my-account/auth/my-account-auth.page.ts create mode 100644 tests/pw/pages/frontend/my-orders/all-my-orders.page.ts create mode 100644 tests/pw/pages/frontend/my-orders/customer-order-details.page.ts create mode 100644 tests/pw/pages/frontend/shop/shop.page.ts create mode 100644 tests/pw/pages/frontend/shop/single-product.page.ts create mode 100644 tests/pw/pages/frontend/vendor-dashboard/common/vendor-sidebar.page.ts create mode 100644 tests/pw/pages/frontend/vendor-dashboard/orders/vendor-all-orders.page.ts create mode 100644 tests/pw/pages/frontend/vendor-dashboard/orders/vendor-edit-order.page.ts create mode 100644 tests/pw/pages/frontend/vendor-dashboard/products/product-add-edit.page.ts create mode 100644 tests/pw/pages/frontend/vendor-dashboard/products/products-list.page.ts create mode 100644 tests/pw/pages/frontend/vendor-dashboard/settings/store/vendor-store.page.ts create mode 100644 tests/pw/pages/wp-admin/common/sidebar.page.ts create mode 100644 tests/pw/pages/wp-admin/dokan/settings/modules.page.ts create mode 100644 tests/pw/pages/wp-admin/dokan/settings/shipping-status.page.ts create mode 100644 tests/pw/pages/wp-admin/products/all-products.page.ts create mode 100644 tests/pw/pages/wp-admin/products/edit-product.page.ts 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 new file mode 100644 index 0000000000..94d9c29b20 --- /dev/null +++ b/tests/pw/pages/frontend/my-account/auth/my-account-auth.page.ts @@ -0,0 +1,32 @@ +import { BasePage } from '@pages/basePage'; +import { Page } from '@playwright/test'; + +export default class MyAccountAuthPage extends BasePage { + constructor(page: Page) { + super(page); + } + + 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); + } + + async enterPassword(password: string) { + await this.passwordInputField().fill(password); + } + + async clickOnLoginButton() { + await this.loginButton().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 new file mode 100644 index 0000000000..a2118dcbf0 --- /dev/null +++ b/tests/pw/pages/frontend/my-orders/all-my-orders.page.ts @@ -0,0 +1,16 @@ +import { BasePage } from '@pages/basePage'; +import { Page } from '@playwright/test'; + +export default class AllMyOrdersPage extends BasePage { + constructor(page: Page) { + super(page); + } + + 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(); + } +} 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 new file mode 100644 index 0000000000..e84d425935 --- /dev/null +++ b/tests/pw/pages/frontend/my-orders/customer-order-details.page.ts @@ -0,0 +1,28 @@ +import { BasePage } from '@pages/basePage'; +import { Page } from '@playwright/test'; + +export default class CustomerOrderDetailsPage extends BasePage { + constructor(page: Page) { + super(page); + } + + 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(); + } + + async clickOnDialogBoxOkButton() { + await this.dialogueBoxOkButton().click(); + } +} diff --git a/tests/pw/pages/frontend/shop/shop.page.ts b/tests/pw/pages/frontend/shop/shop.page.ts new file mode 100644 index 0000000000..88b9401893 --- /dev/null +++ b/tests/pw/pages/frontend/shop/shop.page.ts @@ -0,0 +1,16 @@ +import { BasePage } from '@pages/basePage'; +import { Page } from '@playwright/test'; + +export default class ShopPage extends BasePage { + constructor(page: Page) { + super(page); + } + + productTitle() { + return this.page.locator('.woocommerce-loop-product__title'); + } + + async clickOnProductWithTitle(productTitle: string) { + await this.productTitle().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 new file mode 100644 index 0000000000..b491b75841 --- /dev/null +++ b/tests/pw/pages/frontend/shop/single-product.page.ts @@ -0,0 +1,20 @@ +import { BasePage } from '@pages/basePage'; +import { Page } from '@playwright/test'; + +export default class SingleProductPage extends BasePage { + constructor(page: Page) { + super(page); + } + + addToCartButton() { + return this.page.locator('.single_add_to_cart_button'); + } + + errorMessageElement() { + return this.page.locator('//ul[@class="woocommerce-error"]/li'); + } + + async clickOnAddToCartButton() { + await this.addToCartButton().click(); + } +} diff --git a/tests/pw/pages/frontend/vendor-dashboard/common/vendor-sidebar.page.ts b/tests/pw/pages/frontend/vendor-dashboard/common/vendor-sidebar.page.ts new file mode 100644 index 0000000000..3474a05b11 --- /dev/null +++ b/tests/pw/pages/frontend/vendor-dashboard/common/vendor-sidebar.page.ts @@ -0,0 +1,25 @@ +import { BasePage } from '@pages/basePage'; +import { Page } from '@playwright/test'; + +export default class VendorDashboardSidebarPage extends BasePage { + constructor(page: Page) { + super(page); + } + + sidebarMenu(title: string) { + // return this.page.locator(`//li[@class="${title}"]/a`); + return this.page.locator(`//li[contains(@class, "${title}")]/a`); + } + + async clickOnOrdersTab() { + await this.sidebarMenu('orders').click(); + } + + async clickOnProductsTab() { + await this.sidebarMenu('products').click(); + } + + async clickOnSettingsTab() { + await this.sidebarMenu('settings').click(); + } +} diff --git a/tests/pw/pages/frontend/vendor-dashboard/orders/vendor-all-orders.page.ts b/tests/pw/pages/frontend/vendor-dashboard/orders/vendor-all-orders.page.ts new file mode 100644 index 0000000000..69acba6f78 --- /dev/null +++ b/tests/pw/pages/frontend/vendor-dashboard/orders/vendor-all-orders.page.ts @@ -0,0 +1,16 @@ +import { BasePage } from '@pages/basePage'; +import { Page } from '@playwright/test'; + +export default class VendorAllOrdersPage extends BasePage { + constructor(page: Page) { + super(page); + } + + orderTitleById(orderId: string) { + return this.page.locator(`//td[@data-title="Order"]/a/strong[text()="Order ${orderId}"]`); + } + + async clickOnOrderById(orderId: string) { + await this.orderTitleById(orderId).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 new file mode 100644 index 0000000000..c754d2f257 --- /dev/null +++ b/tests/pw/pages/frontend/vendor-dashboard/orders/vendor-edit-order.page.ts @@ -0,0 +1,64 @@ +import { BasePage } from '@pages/basePage'; +import { Page } from '@playwright/test'; + +export default class VendorEditOrderPage extends BasePage { + constructor(page: Page) { + super(page); + } + + 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(); + } + + async clickOnShipmentItemCheckboxByIndex(itemNumber: string) { + await this.shipmentItemCheckboxByIndex(itemNumber).click(); + } + + async selectShippingStatus(status: string) { + await this.shippingStatusDropdown().selectOption(status); + } + + async selectShippingProvider(providerName: string) { + await this.shippingProviderDropdown().selectOption(providerName); + } + + async enterShippingDate(date: string) { + await this.shippingDateField().fill(date); + } + + async enterShippingTrackingNumber(trackingNumber: string) { + await this.shippingTrackingNumberField().fill(trackingNumber); + } + + async clickOnCreateShipmentButton() { + await this.createShipmentButton().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 new file mode 100644 index 0000000000..1b448e87c3 --- /dev/null +++ b/tests/pw/pages/frontend/vendor-dashboard/products/product-add-edit.page.ts @@ -0,0 +1,40 @@ +import { BasePage } from '@pages/basePage'; +import { Page } from '@playwright/test'; + +export default class VendorProductAddEditPage extends BasePage { + constructor(page: Page) { + super(page); + } + + 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); + } + + async enterSimpleProductMaxQty(quantity: string) { + await this.simpleProductMaxQtyInputField().fill(quantity); + } + + async selectProductStatus(status: 'publish' | 'draft' | 'pending') { + await this.productStatusSelectField().selectOption(status); + } + + async clickOnSaveProduct() { + await this.saveProductButton().click(); + } +} diff --git a/tests/pw/pages/frontend/vendor-dashboard/products/products-list.page.ts b/tests/pw/pages/frontend/vendor-dashboard/products/products-list.page.ts new file mode 100644 index 0000000000..500fefb699 --- /dev/null +++ b/tests/pw/pages/frontend/vendor-dashboard/products/products-list.page.ts @@ -0,0 +1,16 @@ +import { BasePage } from '@pages/basePage'; +import { Page } from '@playwright/test'; + +export default class VendorProductListPage extends BasePage { + constructor(page: Page) { + super(page); + } + + productTitle() { + return this.page.locator(`//td[@data-title="Name"]/strong/a`); + } + + async clickOnProductWithTitle(productTitle: string) { + await this.productTitle().getByText(productTitle).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 new file mode 100644 index 0000000000..6dc0d5c531 --- /dev/null +++ b/tests/pw/pages/frontend/vendor-dashboard/settings/store/vendor-store.page.ts @@ -0,0 +1,28 @@ +import { BasePage } from '@pages/basePage'; +import { Page } from '@playwright/test'; + +export default class VendorStoreSettingsPage extends BasePage { + constructor(page: Page) { + super(page); + } + + 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 enterMaximumOrderAmount(amount: string) { + await this.maximumOrderAmountInputField().fill(amount); + } + + async clickOnUpdateSettingsButton() { + await this.updateSettingsButton().click(); + } +} diff --git a/tests/pw/pages/wp-admin/common/sidebar.page.ts b/tests/pw/pages/wp-admin/common/sidebar.page.ts new file mode 100644 index 0000000000..94c6565be6 --- /dev/null +++ b/tests/pw/pages/wp-admin/common/sidebar.page.ts @@ -0,0 +1,20 @@ +import { BasePage } from '@pages/basePage'; +import { Page } from '@playwright/test'; + +export default class WpAdminSidebar extends BasePage { + constructor(page: Page) { + super(page); + } + + sideMenu(title: string) { + return this.page.locator('.wp-menu-name').getByText(title); + } + + async clickOnProductsLink() { + await this.sideMenu('Products').click(); + } + + async clickOnDokanLink() { + await this.sideMenu('Dokan').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 new file mode 100644 index 0000000000..b252d554cd --- /dev/null +++ b/tests/pw/pages/wp-admin/dokan/settings/modules.page.ts @@ -0,0 +1,36 @@ +import { BasePage } from '@pages/basePage'; +import { Page } from '@playwright/test'; + +export default class DokanModulesPage extends BasePage { + constructor(page: Page) { + super(page); + } + + 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); + } + + async clickOnModuleToggleButton(moduleName: string) { + await this.moduleToggleField(moduleName).click(); + } + + async clickOnActiveModulesTab() { + await this.activeModuleTab().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 new file mode 100644 index 0000000000..e4c3f57128 --- /dev/null +++ b/tests/pw/pages/wp-admin/dokan/settings/shipping-status.page.ts @@ -0,0 +1,54 @@ +import { BasePage } from '@pages/basePage'; +import { Page } from '@playwright/test'; + +export default class DokanShippingStatusPage extends BasePage { + constructor(page: Page) { + super(page); + } + + 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(); + + let locator; + for (const item of await list) { + const text = await item.textContent(); + if (text?.includes(status)) { + locator = item; + } + } + + return locator; + } + + saveChangesButton() { + return this.page.locator('#submit'); + } + + async clickOnShippingStatusTab() { + await this.shippingStatusTab().click(); + } + + async clickOnAllowShipmentTrackingCheckbox() { + await this.allowShipmentTrackingCheckbox().click(); + } + + async clickOnAllowMarkAsReceivedCheckbox() { + await this.allowMarkAsReceivedCheckbox().click(); + } + + async clickOnSaveChangesButton() { + await this.saveChangesButton().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 new file mode 100644 index 0000000000..5e39fd8b09 --- /dev/null +++ b/tests/pw/pages/wp-admin/products/all-products.page.ts @@ -0,0 +1,16 @@ +import { BasePage } from '@pages/basePage'; +import { Page } from '@playwright/test'; + +export default class AllProductsPage extends BasePage { + constructor(page: Page) { + super(page); + } + + productTitleById(productId: string) { + return this.page.locator(`//tr[@id="post-${productId}"]/td[2]/strong/a`); + } + + async clickOnProductTitleById(productId: string) { + await this.productTitleById(productId).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 new file mode 100644 index 0000000000..1d504b94aa --- /dev/null +++ b/tests/pw/pages/wp-admin/products/edit-product.page.ts @@ -0,0 +1,16 @@ +import { BasePage } from '@pages/basePage'; +import { Page } from '@playwright/test'; + +export default class EditProductPage extends BasePage { + constructor(page: Page) { + super(page); + } + + publishButton() { + return this.page.locator('#publish'); + } + + async clickOnPublishButton() { + await this.publishButton().click(); + } +} From 9f243d504665c5e808b6450c98d0c887114326c1 Mon Sep 17 00:00:00 2001 From: Stalin Date: Thu, 12 Sep 2024 15:24:05 +0600 Subject: [PATCH 02/10] randomstring package added for random string generation --- tests/pw/package-lock.json | 46 ++++++++++++++++++++++++++++++++++++++ tests/pw/package.json | 2 ++ 2 files changed, 48 insertions(+) diff --git a/tests/pw/package-lock.json b/tests/pw/package-lock.json index c6b1c2334c..7b96d4ca21 100644 --- a/tests/pw/package-lock.json +++ b/tests/pw/package-lock.json @@ -15,11 +15,13 @@ "dotenv": "^16.4.5", "mysql2": "^3.11.0", "php-serialize": "^5.0.1", + "randomstring": "^1.3.0", "zod": "^3.23.8" }, "devDependencies": { "@types/js-yaml": "^4.0.9", "@types/node": "^22.3.0", + "@types/randomstring": "^1.3.0", "@typescript-eslint/eslint-plugin": "^8.1.0", "@typescript-eslint/parser": "^8.1.0", "eslint": "8.57", @@ -269,6 +271,12 @@ "undici-types": "~6.18.2" } }, + "node_modules/@types/randomstring": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@types/randomstring/-/randomstring-1.3.0.tgz", + "integrity": "sha512-kCP61wludjY7oNUeFiMxfswHB3Wn/aC03Cu82oQsNTO6OCuhVN/rCbBs68Cq6Nkgjmp2Sh3Js6HearJPkk7KQA==", + "dev": true + }, "node_modules/@types/responselike": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/@types/responselike/-/responselike-1.0.1.tgz", @@ -2337,6 +2345,25 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/randombytes": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.0.3.tgz", + "integrity": "sha512-lDVjxQQFoCG1jcrP06LNo2lbWp4QTShEXnhActFBwYuHprllQV6VUpwreApsYqCgD+N1mHoqJ/BI/4eV4R2GYg==" + }, + "node_modules/randomstring": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/randomstring/-/randomstring-1.3.0.tgz", + "integrity": "sha512-gY7aQ4i1BgwZ8I1Op4YseITAyiDiajeZOPQUbIq9TPGPhUm5FX59izIaOpmKbME1nmnEiABf28d9K2VSii6BBg==", + "dependencies": { + "randombytes": "2.0.3" + }, + "bin": { + "randomstring": "bin/randomstring" + }, + "engines": { + "node": "*" + } + }, "node_modules/readable-stream": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz", @@ -3032,6 +3059,12 @@ "undici-types": "~6.18.2" } }, + "@types/randomstring": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@types/randomstring/-/randomstring-1.3.0.tgz", + "integrity": "sha512-kCP61wludjY7oNUeFiMxfswHB3Wn/aC03Cu82oQsNTO6OCuhVN/rCbBs68Cq6Nkgjmp2Sh3Js6HearJPkk7KQA==", + "dev": true + }, "@types/responselike": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/@types/responselike/-/responselike-1.0.1.tgz", @@ -4495,6 +4528,19 @@ "resolved": "https://registry.npmjs.org/quick-lru/-/quick-lru-5.1.1.tgz", "integrity": "sha512-WuyALRjWPDGtt/wzJiadO5AXY+8hZ80hVpe6MyivgraREW751X3SbhRvG3eLKOYN+8VEvqLcf3wdnt44Z4S4SA==" }, + "randombytes": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.0.3.tgz", + "integrity": "sha512-lDVjxQQFoCG1jcrP06LNo2lbWp4QTShEXnhActFBwYuHprllQV6VUpwreApsYqCgD+N1mHoqJ/BI/4eV4R2GYg==" + }, + "randomstring": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/randomstring/-/randomstring-1.3.0.tgz", + "integrity": "sha512-gY7aQ4i1BgwZ8I1Op4YseITAyiDiajeZOPQUbIq9TPGPhUm5FX59izIaOpmKbME1nmnEiABf28d9K2VSii6BBg==", + "requires": { + "randombytes": "2.0.3" + } + }, "readable-stream": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz", diff --git a/tests/pw/package.json b/tests/pw/package.json index deb07f09f4..fb8bb9e62f 100644 --- a/tests/pw/package.json +++ b/tests/pw/package.json @@ -50,6 +50,7 @@ "devDependencies": { "@types/js-yaml": "^4.0.9", "@types/node": "^22.3.0", + "@types/randomstring": "^1.3.0", "@typescript-eslint/eslint-plugin": "^8.1.0", "@typescript-eslint/parser": "^8.1.0", "eslint": "8.57", @@ -68,6 +69,7 @@ "dotenv": "^16.4.5", "mysql2": "^3.11.0", "php-serialize": "^5.0.1", + "randomstring": "^1.3.0", "zod": "^3.23.8" } } From 9d189ab3751013431718ad9d7282be5459e0f8fb Mon Sep 17 00:00:00 2001 From: Stalin Date: Thu, 12 Sep 2024 15:24:37 +0600 Subject: [PATCH 03/10] order min-max test cases added --- .../e2e/order-min-max/min-max-01.spec.ts | 32 ++++ .../e2e/order-min-max/min-max-02.spec.ts | 171 ++++++++++++++++++ 2 files changed, 203 insertions(+) create mode 100644 tests/pw/tests/e2e/order-min-max/min-max-01.spec.ts create mode 100644 tests/pw/tests/e2e/order-min-max/min-max-02.spec.ts diff --git a/tests/pw/tests/e2e/order-min-max/min-max-01.spec.ts b/tests/pw/tests/e2e/order-min-max/min-max-01.spec.ts new file mode 100644 index 0000000000..7e05429a24 --- /dev/null +++ b/tests/pw/tests/e2e/order-min-max/min-max-01.spec.ts @@ -0,0 +1,32 @@ +import { LoginPage } from '@pages/loginPage'; +import DokanModulesPage from '@pages/wp-admin/dokan/settings/modules.page'; +import test, { expect } from '@playwright/test'; + +import 'dotenv/config'; +const { ADMIN, ADMIN_PASSWORD } = process.env; + +let baseUrl: string; +let loginPage: LoginPage; + +test.describe('Order Min-Max - Module Activation', () => { + test.beforeEach(async ({ page }, testInfo) => { + loginPage = new LoginPage(page); + baseUrl = testInfo.project.use.baseURL as string; + await page.goto(baseUrl); + }); + + test('Admin is able to enable min-max feature from modules page', { tag: ['@lite', '@admin'] }, async ({ page }) => { + let modulesPage = new DokanModulesPage(page); + + await loginPage.adminLogin({ username: ADMIN, password: ADMIN_PASSWORD }); + await page.goto(baseUrl + '/wp-admin/admin.php?page=dokan#/modules'); + await modulesPage.searchFor('Min Max Quantities'); + await modulesPage.clickOnModuleToggleButton('Min Max Quantities'); + await modulesPage.clickOnActiveModulesTab(); + + await page.waitForTimeout(2000); + const titleList = await modulesPage.moduleTitle().allInnerTexts(); + + expect(titleList.includes('Min Max Quantities')).toEqual(true); + }); +}); diff --git a/tests/pw/tests/e2e/order-min-max/min-max-02.spec.ts b/tests/pw/tests/e2e/order-min-max/min-max-02.spec.ts new file mode 100644 index 0000000000..f3fa756b2c --- /dev/null +++ b/tests/pw/tests/e2e/order-min-max/min-max-02.spec.ts @@ -0,0 +1,171 @@ +import test, { Browser, chromium, expect, Page } from '@playwright/test'; +import { ApiUtils } from '@utils/apiUtils'; +import { payloads } from '@utils/payloads'; +import randomstring from 'randomstring'; + +import 'dotenv/config'; +import VendorDashboardSidebarPage from '@pages/frontend/vendor-dashboard/common/vendor-sidebar.page'; +import MyAccountAuthPage from '@pages/frontend/my-account/auth/my-account-auth.page'; +import VendorProductListPage from '@pages/frontend/vendor-dashboard/products/products-list.page'; +import VendorProductAddEditPage from '@pages/frontend/vendor-dashboard/products/product-add-edit.page'; +import ShopPage from '@pages/frontend/shop/shop.page'; +import SingleProductPage from '@pages/frontend/shop/single-product.page'; +import VendorStoreSettingsPage from '@pages/frontend/vendor-dashboard/settings/store/vendor-store.page'; + +let baseUrl: string; +let api: ApiUtils; +let productName: string; +let customerEmail: string; +let vendorId: string; +let vendorEmail: string; +let storeName: string; +let storeSettingsPage: VendorStoreSettingsPage; + +let vendorDashboardSidebarPage: VendorDashboardSidebarPage; +let vendorMyAccountAuthPage: MyAccountAuthPage; +let vendorProductListPage: VendorProductListPage; +let vendorProductAddEditPage: VendorProductAddEditPage; +let vendorPage: Page; + +let customerPage: Page; +let customerMyAccountAuthPage: MyAccountAuthPage; +let shopPage: ShopPage; +let singleProductPage: SingleProductPage; + +let vendorBrowser: Browser; +let customerBrowser: Browser; + +test.describe.only('Order Min-Max - Single Product Page', () => { + test.beforeEach(async ({ page, request }, testInfo) => { + baseUrl = testInfo.project.use.baseURL as string; + await page.goto(baseUrl); + api = new ApiUtils(request); + + // create customer + const customer = await api.createCustomer(payloads.createCustomer(), payloads.adminAuth); + customerEmail = customer[0].email; + + // create vendor + const vendor = await api.createStore(payloads.createStore(), payloads.adminAuth); + vendorId = vendor[0].id; + vendorEmail = vendor[0].email; + storeName = vendor[0]['store_name']; + + // // create product + const productTitle = `Automation Simple Product ${vendorId}${randomstring.generate(5)}`; + const product = await api.createProduct( + { + name: productTitle, + type: 'simple', + regular_price: '10', + status: 'publish', + post_author: `${vendorId}`, + categories: [{}], + description: '

test description

', + }, + payloads.adminAuth, + ); + + productName = product[0]['name']; + + // vendor + vendorBrowser = await chromium.launch(); + vendorPage = await vendorBrowser.newPage(); + vendorDashboardSidebarPage = new VendorDashboardSidebarPage(vendorPage); + vendorMyAccountAuthPage = new MyAccountAuthPage(vendorPage); + vendorProductListPage = new VendorProductListPage(vendorPage); + vendorProductAddEditPage = new VendorProductAddEditPage(vendorPage); + storeSettingsPage = new VendorStoreSettingsPage(vendorPage); + + // customer + customerBrowser = await chromium.launch(); + customerPage = await customerBrowser.newPage(); + customerMyAccountAuthPage = new MyAccountAuthPage(customerPage); + shopPage = new ShopPage(customerPage); + singleProductPage = new SingleProductPage(customerPage); + + // vendor login + await vendorPage.goto(baseUrl + '/dashboard/'); + await vendorMyAccountAuthPage.enterUsername(vendorEmail); + await vendorMyAccountAuthPage.enterPassword(process.env.USER_PASSWORD); + await vendorMyAccountAuthPage.clickOnLoginButton(); + + // customer login + await customerPage.goto(baseUrl + '/my-account/'); + await customerMyAccountAuthPage.enterUsername(customerEmail); + await customerMyAccountAuthPage.enterPassword(process.env.USER_PASSWORD); + await customerMyAccountAuthPage.clickOnLoginButton(); + }); + + test.afterEach(async () => { + await vendorBrowser.close(); + await customerBrowser.close(); + }); + + test('Adding more product than max quantity limit displays error in single product page', { tag: ['@lite', '@admin'] }, async () => { + // await vendorPage.goto(baseUrl + '/dashboard/'); + // await vendorMyAccountAuthPage.enterUsername(vendorEmail); + // await vendorMyAccountAuthPage.enterPassword(process.env.USER_PASSWORD); + // await vendorMyAccountAuthPage.clickOnLoginButton(); + + await vendorDashboardSidebarPage.clickOnProductsTab(); + await vendorProductListPage.clickOnProductWithTitle(productName); + + const maxQuantity = '2'; + + await vendorProductAddEditPage.enterSimpleProductMaxQty(maxQuantity); + await vendorProductAddEditPage.selectProductStatus('publish'); + await vendorProductAddEditPage.clickOnSaveProduct(); + + // await customerPage.goto(baseUrl + '/my-account/'); + // await customerMyAccountAuthPage.enterUsername(customerEmail); + // await customerMyAccountAuthPage.enterPassword(process.env.USER_PASSWORD); + // await customerMyAccountAuthPage.clickOnLoginButton(); + + await customerPage.goto(baseUrl + '/shop/'); + await shopPage.clickOnProductWithTitle(productName); + await singleProductPage.clickOnAddToCartButton(); + await singleProductPage.clickOnAddToCartButton(); + await singleProductPage.clickOnAddToCartButton(); + + const errorMessage = await singleProductPage.errorMessageElement().allInnerTexts(); + const expectedErrorMessage = `Maximum allowed quantity for ${productName} is ${maxQuantity}.`; + + expect(errorMessage[0]).toEqual(expectedErrorMessage); + }); + + test('Error displayed in single product page if added product exceeds maximum allowed amount', { tag: ['@lite', '@admin'] }, async () => { + // await vendorPage.goto(baseUrl + '/dashboard/'); + // await vendorMyAccountAuthPage.enterUsername(vendorEmail); + // await vendorMyAccountAuthPage.enterPassword(process.env.USER_PASSWORD); + // await vendorMyAccountAuthPage.clickOnLoginButton(); + + await vendorDashboardSidebarPage.clickOnProductsTab(); + await vendorProductListPage.clickOnProductWithTitle(productName); + + await vendorProductAddEditPage.selectProductStatus('publish'); + await vendorProductAddEditPage.clickOnSaveProduct(); + + const maxAmount = '20'; + + await vendorDashboardSidebarPage.clickOnSettingsTab(); + await storeSettingsPage.enterMaximumOrderAmount(maxAmount); + await storeSettingsPage.clickOnUpdateSettingsButton(); + + // await customerPage.goto(baseUrl + '/my-account/'); + // await customerMyAccountAuthPage.enterUsername(customerEmail); + // await customerMyAccountAuthPage.enterPassword(process.env.USER_PASSWORD); + // await customerMyAccountAuthPage.clickOnLoginButton(); + + await customerPage.goto(baseUrl + '/shop/'); + await shopPage.clickOnProductWithTitle(productName); + await singleProductPage.clickOnAddToCartButton(); + await singleProductPage.clickOnAddToCartButton(); + await singleProductPage.clickOnAddToCartButton(); + + const errorMessage = await singleProductPage.errorMessageElement().allInnerTexts(); + const expectedErrorMessage = `Maximum allowed cart amount for ${storeName} is $${maxAmount}.00. You currently have $20.00 in cart.`; + + expect(errorMessage[0]).toEqual(expectedErrorMessage); + }); +}); From 439d5d5cb30a2d33a592c36f6128777f22ce56fa Mon Sep 17 00:00:00 2001 From: Stalin Date: Thu, 12 Sep 2024 15:31:00 +0600 Subject: [PATCH 04/10] commented code removed --- .../e2e/order-min-max/min-max-02.spec.ts | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/tests/pw/tests/e2e/order-min-max/min-max-02.spec.ts b/tests/pw/tests/e2e/order-min-max/min-max-02.spec.ts index f3fa756b2c..b36827e01c 100644 --- a/tests/pw/tests/e2e/order-min-max/min-max-02.spec.ts +++ b/tests/pw/tests/e2e/order-min-max/min-max-02.spec.ts @@ -103,11 +103,6 @@ test.describe.only('Order Min-Max - Single Product Page', () => { }); test('Adding more product than max quantity limit displays error in single product page', { tag: ['@lite', '@admin'] }, async () => { - // await vendorPage.goto(baseUrl + '/dashboard/'); - // await vendorMyAccountAuthPage.enterUsername(vendorEmail); - // await vendorMyAccountAuthPage.enterPassword(process.env.USER_PASSWORD); - // await vendorMyAccountAuthPage.clickOnLoginButton(); - await vendorDashboardSidebarPage.clickOnProductsTab(); await vendorProductListPage.clickOnProductWithTitle(productName); @@ -117,11 +112,6 @@ test.describe.only('Order Min-Max - Single Product Page', () => { await vendorProductAddEditPage.selectProductStatus('publish'); await vendorProductAddEditPage.clickOnSaveProduct(); - // await customerPage.goto(baseUrl + '/my-account/'); - // await customerMyAccountAuthPage.enterUsername(customerEmail); - // await customerMyAccountAuthPage.enterPassword(process.env.USER_PASSWORD); - // await customerMyAccountAuthPage.clickOnLoginButton(); - await customerPage.goto(baseUrl + '/shop/'); await shopPage.clickOnProductWithTitle(productName); await singleProductPage.clickOnAddToCartButton(); @@ -135,11 +125,6 @@ test.describe.only('Order Min-Max - Single Product Page', () => { }); test('Error displayed in single product page if added product exceeds maximum allowed amount', { tag: ['@lite', '@admin'] }, async () => { - // await vendorPage.goto(baseUrl + '/dashboard/'); - // await vendorMyAccountAuthPage.enterUsername(vendorEmail); - // await vendorMyAccountAuthPage.enterPassword(process.env.USER_PASSWORD); - // await vendorMyAccountAuthPage.clickOnLoginButton(); - await vendorDashboardSidebarPage.clickOnProductsTab(); await vendorProductListPage.clickOnProductWithTitle(productName); @@ -152,11 +137,6 @@ test.describe.only('Order Min-Max - Single Product Page', () => { await storeSettingsPage.enterMaximumOrderAmount(maxAmount); await storeSettingsPage.clickOnUpdateSettingsButton(); - // await customerPage.goto(baseUrl + '/my-account/'); - // await customerMyAccountAuthPage.enterUsername(customerEmail); - // await customerMyAccountAuthPage.enterPassword(process.env.USER_PASSWORD); - // await customerMyAccountAuthPage.clickOnLoginButton(); - await customerPage.goto(baseUrl + '/shop/'); await shopPage.clickOnProductWithTitle(productName); await singleProductPage.clickOnAddToCartButton(); From 0f4eba0ee203175737f2353f13ed919d88c065fe Mon Sep 17 00:00:00 2001 From: Stalin Date: Thu, 12 Sep 2024 16:08:59 +0600 Subject: [PATCH 05/10] class constructor removed --- .../pages/frontend/my-account/auth/my-account-auth.page.ts | 5 ----- tests/pw/pages/frontend/my-orders/all-my-orders.page.ts | 5 ----- .../pages/frontend/my-orders/customer-order-details.page.ts | 5 ----- tests/pw/pages/frontend/shop/shop.page.ts | 5 ----- tests/pw/pages/frontend/shop/single-product.page.ts | 5 ----- .../frontend/vendor-dashboard/common/vendor-sidebar.page.ts | 6 ------ .../vendor-dashboard/orders/vendor-all-orders.page.ts | 5 ----- .../vendor-dashboard/orders/vendor-edit-order.page.ts | 5 ----- .../vendor-dashboard/products/product-add-edit.page.ts | 5 ----- .../vendor-dashboard/products/products-list.page.ts | 5 ----- .../vendor-dashboard/settings/store/vendor-store.page.ts | 5 ----- tests/pw/pages/wp-admin/common/sidebar.page.ts | 5 ----- tests/pw/pages/wp-admin/dokan/settings/modules.page.ts | 5 ----- .../pages/wp-admin/dokan/settings/shipping-status.page.ts | 5 ----- tests/pw/pages/wp-admin/products/all-products.page.ts | 5 ----- tests/pw/pages/wp-admin/products/edit-product.page.ts | 5 ----- 16 files changed, 81 deletions(-) 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 94d9c29b20..bbfbdc9e3a 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,11 +1,6 @@ import { BasePage } from '@pages/basePage'; -import { Page } from '@playwright/test'; export default class MyAccountAuthPage extends BasePage { - constructor(page: Page) { - super(page); - } - usernameInputField() { return this.page.locator('#username'); } 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 a2118dcbf0..bea7e1eb9e 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,6 @@ import { BasePage } from '@pages/basePage'; -import { Page } from '@playwright/test'; export default class AllMyOrdersPage extends BasePage { - constructor(page: Page) { - super(page); - } - viewButtonByOrderId(orderId: string) { return this.page.locator(`//td[@class="order-number"]/a[contains(text(), "${orderId}")]/../following-sibling::td[5]/a`); } 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 e84d425935..fa679188bd 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,11 +1,6 @@ import { BasePage } from '@pages/basePage'; -import { Page } from '@playwright/test'; export default class CustomerOrderDetailsPage extends BasePage { - constructor(page: Page) { - super(page); - } - orderReceivedButtonByShipmentNumber(shipmentNumber: string) { return this.page.locator(`//h4[@class="shippments-tracking-title"]/strong[text()="Shipment ${shipmentNumber} "]/../../div[1]/strong[@class="customer-status"]`); } diff --git a/tests/pw/pages/frontend/shop/shop.page.ts b/tests/pw/pages/frontend/shop/shop.page.ts index 88b9401893..54e5ba10f1 100644 --- a/tests/pw/pages/frontend/shop/shop.page.ts +++ b/tests/pw/pages/frontend/shop/shop.page.ts @@ -1,11 +1,6 @@ import { BasePage } from '@pages/basePage'; -import { Page } from '@playwright/test'; export default class ShopPage extends BasePage { - constructor(page: Page) { - super(page); - } - productTitle() { return this.page.locator('.woocommerce-loop-product__title'); } diff --git a/tests/pw/pages/frontend/shop/single-product.page.ts b/tests/pw/pages/frontend/shop/single-product.page.ts index b491b75841..a28ca1316d 100644 --- a/tests/pw/pages/frontend/shop/single-product.page.ts +++ b/tests/pw/pages/frontend/shop/single-product.page.ts @@ -1,11 +1,6 @@ import { BasePage } from '@pages/basePage'; -import { Page } from '@playwright/test'; export default class SingleProductPage extends BasePage { - constructor(page: Page) { - super(page); - } - addToCartButton() { return this.page.locator('.single_add_to_cart_button'); } diff --git a/tests/pw/pages/frontend/vendor-dashboard/common/vendor-sidebar.page.ts b/tests/pw/pages/frontend/vendor-dashboard/common/vendor-sidebar.page.ts index 3474a05b11..ab286a5bcd 100644 --- a/tests/pw/pages/frontend/vendor-dashboard/common/vendor-sidebar.page.ts +++ b/tests/pw/pages/frontend/vendor-dashboard/common/vendor-sidebar.page.ts @@ -1,13 +1,7 @@ import { BasePage } from '@pages/basePage'; -import { Page } from '@playwright/test'; export default class VendorDashboardSidebarPage extends BasePage { - constructor(page: Page) { - super(page); - } - sidebarMenu(title: string) { - // return this.page.locator(`//li[@class="${title}"]/a`); return this.page.locator(`//li[contains(@class, "${title}")]/a`); } diff --git a/tests/pw/pages/frontend/vendor-dashboard/orders/vendor-all-orders.page.ts b/tests/pw/pages/frontend/vendor-dashboard/orders/vendor-all-orders.page.ts index 69acba6f78..4c06566545 100644 --- a/tests/pw/pages/frontend/vendor-dashboard/orders/vendor-all-orders.page.ts +++ b/tests/pw/pages/frontend/vendor-dashboard/orders/vendor-all-orders.page.ts @@ -1,11 +1,6 @@ import { BasePage } from '@pages/basePage'; -import { Page } from '@playwright/test'; export default class VendorAllOrdersPage extends BasePage { - constructor(page: Page) { - super(page); - } - orderTitleById(orderId: string) { return this.page.locator(`//td[@data-title="Order"]/a/strong[text()="Order ${orderId}"]`); } 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 c754d2f257..901a7ffb1a 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,11 +1,6 @@ import { BasePage } from '@pages/basePage'; -import { Page } from '@playwright/test'; export default class VendorEditOrderPage extends BasePage { - constructor(page: Page) { - super(page); - } - createNewShipmentButton() { return this.page.locator('#create-tracking-status-action'); } 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 1b448e87c3..3c152817ae 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,11 +1,6 @@ import { BasePage } from '@pages/basePage'; -import { Page } from '@playwright/test'; export default class VendorProductAddEditPage extends BasePage { - constructor(page: Page) { - super(page); - } - simpleProductMinQtyInputField() { return this.page.locator('#dokan_simple_product_min_quantity'); } diff --git a/tests/pw/pages/frontend/vendor-dashboard/products/products-list.page.ts b/tests/pw/pages/frontend/vendor-dashboard/products/products-list.page.ts index 500fefb699..254b935ad5 100644 --- a/tests/pw/pages/frontend/vendor-dashboard/products/products-list.page.ts +++ b/tests/pw/pages/frontend/vendor-dashboard/products/products-list.page.ts @@ -1,11 +1,6 @@ import { BasePage } from '@pages/basePage'; -import { Page } from '@playwright/test'; export default class VendorProductListPage extends BasePage { - constructor(page: Page) { - super(page); - } - productTitle() { return this.page.locator(`//td[@data-title="Name"]/strong/a`); } 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 6dc0d5c531..fa952c8986 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,11 +1,6 @@ import { BasePage } from '@pages/basePage'; -import { Page } from '@playwright/test'; export default class VendorStoreSettingsPage extends BasePage { - constructor(page: Page) { - super(page); - } - minimumOrderAmountInputField() { return this.page.locator('#min_amount_to_order'); } diff --git a/tests/pw/pages/wp-admin/common/sidebar.page.ts b/tests/pw/pages/wp-admin/common/sidebar.page.ts index 94c6565be6..60e60f490e 100644 --- a/tests/pw/pages/wp-admin/common/sidebar.page.ts +++ b/tests/pw/pages/wp-admin/common/sidebar.page.ts @@ -1,11 +1,6 @@ import { BasePage } from '@pages/basePage'; -import { Page } from '@playwright/test'; export default class WpAdminSidebar extends BasePage { - constructor(page: Page) { - super(page); - } - sideMenu(title: string) { return this.page.locator('.wp-menu-name').getByText(title); } 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 b252d554cd..2ad30a4c50 100644 --- a/tests/pw/pages/wp-admin/dokan/settings/modules.page.ts +++ b/tests/pw/pages/wp-admin/dokan/settings/modules.page.ts @@ -1,11 +1,6 @@ import { BasePage } from '@pages/basePage'; -import { Page } from '@playwright/test'; export default class DokanModulesPage extends BasePage { - constructor(page: Page) { - super(page); - } - searchInputField() { return this.page.locator('//div[@class="search-box"]/input'); } 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 e4c3f57128..f8a3f66329 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,11 +1,6 @@ import { BasePage } from '@pages/basePage'; -import { Page } from '@playwright/test'; export default class DokanShippingStatusPage extends BasePage { - constructor(page: Page) { - super(page); - } - shippingStatusTab() { return this.page.locator('//div[@class="nav-title"][text()="Shipping Status"]'); } 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 5e39fd8b09..fb1f08618c 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,6 @@ import { BasePage } from '@pages/basePage'; -import { Page } from '@playwright/test'; export default class AllProductsPage extends BasePage { - constructor(page: Page) { - super(page); - } - productTitleById(productId: string) { return this.page.locator(`//tr[@id="post-${productId}"]/td[2]/strong/a`); } 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 1d504b94aa..9914bccda3 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,6 @@ import { BasePage } from '@pages/basePage'; -import { Page } from '@playwright/test'; export default class EditProductPage extends BasePage { - constructor(page: Page) { - super(page); - } - publishButton() { return this.page.locator('#publish'); } From db8f058577e48db4e4b285e5311ac5b987ade70c Mon Sep 17 00:00:00 2001 From: Stalin Date: Fri, 13 Sep 2024 12:53:16 +0600 Subject: [PATCH 06/10] storefront page objects added --- tests/pw/pages/frontend/cart.page.ts | 27 +++++++++++++++++++ .../frontend/navigation/main-menu.page.ts | 11 ++++++++ 2 files changed, 38 insertions(+) create mode 100644 tests/pw/pages/frontend/cart.page.ts create mode 100644 tests/pw/pages/frontend/navigation/main-menu.page.ts diff --git a/tests/pw/pages/frontend/cart.page.ts b/tests/pw/pages/frontend/cart.page.ts new file mode 100644 index 0000000000..02cb9ceba4 --- /dev/null +++ b/tests/pw/pages/frontend/cart.page.ts @@ -0,0 +1,27 @@ +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"]'); + } + + woocommerceErrorMessage() { + return this.page.locator('//div[@class="woocommerce-notices-wrapper"]/ul[@class="woocommerce-error"]/li'); + } + + async enterQuantityValue(productTitle: string, quantityValue: string) { + await this.quantityInputFieldFor(productTitle).fill(quantityValue); + } + + async clickOnUpdateCartButton() { + await this.updateCartButton().click(); + } +} diff --git a/tests/pw/pages/frontend/navigation/main-menu.page.ts b/tests/pw/pages/frontend/navigation/main-menu.page.ts new file mode 100644 index 0000000000..491727a748 --- /dev/null +++ b/tests/pw/pages/frontend/navigation/main-menu.page.ts @@ -0,0 +1,11 @@ +import { BasePage } from '@pages/basePage'; + +export default class StorefrontMainMenu extends BasePage { + cartContentLink() { + return this.page.locator('.cart-contents'); + } + + async clickOnCartContentLink() { + await this.cartContentLink().click(); + } +} From 328e2fea7af01c8dd115b3ca327689d5fef0ae4d Mon Sep 17 00:00:00 2001 From: Stalin Date: Fri, 13 Sep 2024 12:54:39 +0600 Subject: [PATCH 07/10] storefront page objects updated --- tests/pw/pages/frontend/shop/single-product.page.ts | 8 ++++++++ .../vendor-dashboard/settings/store/vendor-store.page.ts | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/tests/pw/pages/frontend/shop/single-product.page.ts b/tests/pw/pages/frontend/shop/single-product.page.ts index a28ca1316d..24cb13078a 100644 --- a/tests/pw/pages/frontend/shop/single-product.page.ts +++ b/tests/pw/pages/frontend/shop/single-product.page.ts @@ -1,6 +1,10 @@ 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'); } @@ -9,6 +13,10 @@ export default class SingleProductPage extends BasePage { return this.page.locator('//ul[@class="woocommerce-error"]/li'); } + async enterQuantityValue(productTitle: string, quantityValue: string) { + await this.quantityInputFieldFor(productTitle).fill(quantityValue); + } + async clickOnAddToCartButton() { await this.addToCartButton().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 fa952c8986..d1b29313f4 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 @@ -13,6 +13,10 @@ export default class VendorStoreSettingsPage extends BasePage { return this.page.locator(`//input[@name="dokan_update_store_settings"]`); } + async enterMinimumOrderAmount(amount: string) { + await this.minimumOrderAmountInputField().fill(amount); + } + async enterMaximumOrderAmount(amount: string) { await this.maximumOrderAmountInputField().fill(amount); } From 78aa53acfaaea728e97aed37d77b7927df37f00d Mon Sep 17 00:00:00 2001 From: Stalin Date: Fri, 13 Sep 2024 12:55:19 +0600 Subject: [PATCH 08/10] min-max cart page test cases added --- .../e2e/order-min-max/min-max-02.spec.ts | 2 +- .../e2e/order-min-max/min-max-03.spec.ts | 204 ++++++++++++++++++ 2 files changed, 205 insertions(+), 1 deletion(-) create mode 100644 tests/pw/tests/e2e/order-min-max/min-max-03.spec.ts diff --git a/tests/pw/tests/e2e/order-min-max/min-max-02.spec.ts b/tests/pw/tests/e2e/order-min-max/min-max-02.spec.ts index b36827e01c..031ffbb81a 100644 --- a/tests/pw/tests/e2e/order-min-max/min-max-02.spec.ts +++ b/tests/pw/tests/e2e/order-min-max/min-max-02.spec.ts @@ -35,7 +35,7 @@ let singleProductPage: SingleProductPage; let vendorBrowser: Browser; let customerBrowser: Browser; -test.describe.only('Order Min-Max - Single Product Page', () => { +test.describe('Order Min-Max - Single Product Page', () => { test.beforeEach(async ({ page, request }, testInfo) => { baseUrl = testInfo.project.use.baseURL as string; await page.goto(baseUrl); diff --git a/tests/pw/tests/e2e/order-min-max/min-max-03.spec.ts b/tests/pw/tests/e2e/order-min-max/min-max-03.spec.ts new file mode 100644 index 0000000000..0e780cf6a6 --- /dev/null +++ b/tests/pw/tests/e2e/order-min-max/min-max-03.spec.ts @@ -0,0 +1,204 @@ +import test, { Browser, chromium, expect, Page } from '@playwright/test'; +import { ApiUtils } from '@utils/apiUtils'; +import { payloads } from '@utils/payloads'; +import randomstring from 'randomstring'; + +import 'dotenv/config'; +import VendorDashboardSidebarPage from '@pages/frontend/vendor-dashboard/common/vendor-sidebar.page'; +import MyAccountAuthPage from '@pages/frontend/my-account/auth/my-account-auth.page'; +import VendorProductListPage from '@pages/frontend/vendor-dashboard/products/products-list.page'; +import VendorProductAddEditPage from '@pages/frontend/vendor-dashboard/products/product-add-edit.page'; +import ShopPage from '@pages/frontend/shop/shop.page'; +import SingleProductPage from '@pages/frontend/shop/single-product.page'; +import VendorStoreSettingsPage from '@pages/frontend/vendor-dashboard/settings/store/vendor-store.page'; +import CartPage from '@pages/frontend/cart.page'; +import StorefrontMainMenu from '@pages/frontend/navigation/main-menu.page'; + +let baseUrl: string; +let api: ApiUtils; +let productName: string; +let customerEmail: string; +let vendorId: string; +let vendorEmail: string; +let storeName: string; +let storeSettingsPage: VendorStoreSettingsPage; + +let vendorDashboardSidebarPage: VendorDashboardSidebarPage; +let vendorMyAccountAuthPage: MyAccountAuthPage; +let vendorProductListPage: VendorProductListPage; +let vendorProductAddEditPage: VendorProductAddEditPage; +let vendorPage: Page; + +let customerPage: Page; +let customerMyAccountAuthPage: MyAccountAuthPage; +let shopPage: ShopPage; +let singleProductPage: SingleProductPage; +let cartPage: CartPage; +let storefrontMainMenu: StorefrontMainMenu; + +let vendorBrowser: Browser; +let customerBrowser: Browser; + +test.describe.only('Order Min-Max - Cart Page', () => { + test.beforeEach(async ({ page, request }, testInfo) => { + baseUrl = testInfo.project.use.baseURL as string; + await page.goto(baseUrl); + api = new ApiUtils(request); + + // create customer + const customer = await api.createCustomer(payloads.createCustomer(), payloads.adminAuth); + customerEmail = customer[0].email; + + // create vendor + const vendor = await api.createStore(payloads.createStore(), payloads.adminAuth); + vendorId = vendor[0].id; + vendorEmail = vendor[0].email; + storeName = vendor[0]['store_name']; + + // // create product + const title = `Automation Simple Product ${vendorId}${randomstring.generate(5)}`; + const product = await api.createProduct( + { + name: title, + type: 'simple', + regular_price: '10', + status: 'publish', + post_author: `${vendorId}`, + categories: [{}], + description: '

test description

', + }, + payloads.adminAuth, + ); + + productName = product[0]['name']; + + // vendor + vendorBrowser = await chromium.launch(); + vendorPage = await vendorBrowser.newPage(); + vendorDashboardSidebarPage = new VendorDashboardSidebarPage(vendorPage); + vendorMyAccountAuthPage = new MyAccountAuthPage(vendorPage); + vendorProductListPage = new VendorProductListPage(vendorPage); + vendorProductAddEditPage = new VendorProductAddEditPage(vendorPage); + storeSettingsPage = new VendorStoreSettingsPage(vendorPage); + + // customer + customerBrowser = await chromium.launch(); + customerPage = await customerBrowser.newPage(); + customerMyAccountAuthPage = new MyAccountAuthPage(customerPage); + shopPage = new ShopPage(customerPage); + singleProductPage = new SingleProductPage(customerPage); + cartPage = new CartPage(customerPage); + storefrontMainMenu = new StorefrontMainMenu(customerPage); + + // vendor login + await vendorPage.goto(baseUrl + '/dashboard/'); + await vendorMyAccountAuthPage.enterUsername(vendorEmail); + await vendorMyAccountAuthPage.enterPassword(process.env.USER_PASSWORD); + await vendorMyAccountAuthPage.clickOnLoginButton(); + + // customer login + await customerPage.goto(baseUrl + '/my-account/'); + await customerMyAccountAuthPage.enterUsername(customerEmail); + await customerMyAccountAuthPage.enterPassword(process.env.USER_PASSWORD); + await customerMyAccountAuthPage.clickOnLoginButton(); + }); + + test.afterEach(async () => { + await vendorBrowser.close(); + await customerBrowser.close(); + }); + + test('Product quantity should not be more than maximum limit', { tag: ['@lite', '@admin'] }, async () => { + // vendor + await vendorDashboardSidebarPage.clickOnProductsTab(); + await vendorProductListPage.clickOnProductWithTitle(productName); + await vendorProductAddEditPage.enterSimpleProductMaxQty('4'); + await vendorProductAddEditPage.selectProductStatus('publish'); + await vendorProductAddEditPage.clickOnSaveProduct(); + + // customer + await customerPage.goto(baseUrl + '/shop/'); + await shopPage.clickOnProductWithTitle(productName); + await singleProductPage.clickOnAddToCartButton(); + await customerPage.goto(baseUrl + '/cart/'); + await cartPage.enterQuantityValue(productName, '5'); + await cartPage.clickOnUpdateCartButton(); + + const quantityErrorMessage = await cartPage.quantityErrorElement().textContent(); + const woocommerceError = await cartPage.woocommerceErrorMessage().textContent(); + + expect(quantityErrorMessage?.includes(`Maximum 4 allowed`)).toBeTruthy(); + expect(woocommerceError?.includes(`Maximum allowed quantity for ${productName} is 4.`)).toBeTruthy(); + }); + + test('Product quantity should not be less than minimum limit', { tag: ['@lite', '@admin'] }, async () => { + // vendor + await vendorDashboardSidebarPage.clickOnProductsTab(); + await vendorProductListPage.clickOnProductWithTitle(productName); + await vendorProductAddEditPage.enterSimpleProductMinQty('3'); + await vendorProductAddEditPage.selectProductStatus('publish'); + await vendorProductAddEditPage.clickOnSaveProduct(); + + // customer + await customerPage.goto(baseUrl + '/shop/'); + await shopPage.clickOnProductWithTitle(productName); + await singleProductPage.clickOnAddToCartButton(); + await customerPage.goto(baseUrl + '/cart/'); + await cartPage.enterQuantityValue(productName, '2'); + await cartPage.clickOnUpdateCartButton(); + + const quantityErrorMessage = await cartPage.quantityErrorElement().textContent(); + const woocommerceError = await cartPage.woocommerceErrorMessage().textContent(); + + expect(quantityErrorMessage?.includes(`Minimum 3 required`)).toBeTruthy(); + expect(woocommerceError?.includes(`Minimum required quantity for ${productName} is 3.`)).toBeTruthy(); + }); + + test('Cart total should not be more than maximum amount limit', { tag: ['@lite', '@admin'] }, async () => { + // vendor + await vendorDashboardSidebarPage.clickOnProductsTab(); + await vendorProductListPage.clickOnProductWithTitle(productName); + await vendorProductAddEditPage.selectProductStatus('publish'); + await vendorProductAddEditPage.clickOnSaveProduct(); + + await vendorDashboardSidebarPage.clickOnSettingsTab(); + await storeSettingsPage.enterMaximumOrderAmount('30'); + await storeSettingsPage.clickOnUpdateSettingsButton(); + + // customer + await customerPage.goto(baseUrl + '/shop/'); + await shopPage.clickOnProductWithTitle(productName); + await singleProductPage.clickOnAddToCartButton(); + await customerPage.goto(baseUrl + '/cart/'); + await cartPage.enterQuantityValue(productName, '4'); + await cartPage.clickOnUpdateCartButton(); + + const woocommerceError = await cartPage.woocommerceErrorMessage().textContent(); + + expect(woocommerceError?.trim()).toEqual(`Maximum allowed cart amount for ${storeName} is $30.00. You currently have $40.00 in cart.`); + }); + + test.only('Cart total should not be less than minimum amount limit', { tag: ['@lite', '@admin'] }, async () => { + // vendor + await vendorDashboardSidebarPage.clickOnProductsTab(); + await vendorProductListPage.clickOnProductWithTitle(productName); + await vendorProductAddEditPage.selectProductStatus('publish'); + await vendorProductAddEditPage.clickOnSaveProduct(); + + await vendorDashboardSidebarPage.clickOnSettingsTab(); + await storeSettingsPage.enterMinimumOrderAmount('30'); + await storeSettingsPage.clickOnUpdateSettingsButton(); + + // customer + await customerPage.goto(baseUrl + '/shop/'); + await shopPage.clickOnProductWithTitle(productName); + await singleProductPage.enterQuantityValue(productName, '2'); + await singleProductPage.clickOnAddToCartButton(); + await customerPage.goto(baseUrl + '/cart/'); + await storefrontMainMenu.clickOnCartContentLink(); + + const woocommerceError = await cartPage.woocommerceErrorMessage().textContent(); + + expect(woocommerceError?.trim()).toEqual(`Minimum required cart amount for ${storeName} is $30.00. You currently have $20.00 in cart.`); + }); +}); From 09f5490b905cac37e9c5279d05c1e13f70a36225 Mon Sep 17 00:00:00 2001 From: Stalin <34745567+StalinDurjo@users.noreply.github.com> Date: Wed, 8 Jan 2025 00:05:08 +0600 Subject: [PATCH 09/10] test case updated --- .../e2e/order-min-max/min-max-01.spec.ts | 159 ++++++++++++-- .../e2e/order-min-max/min-max-02.spec.ts | 144 +++++++++---- .../e2e/order-min-max/min-max-03.spec.ts | 204 ------------------ 3 files changed, 234 insertions(+), 273 deletions(-) delete mode 100644 tests/pw/tests/e2e/order-min-max/min-max-03.spec.ts diff --git a/tests/pw/tests/e2e/order-min-max/min-max-01.spec.ts b/tests/pw/tests/e2e/order-min-max/min-max-01.spec.ts index 7e05429a24..39c4861257 100644 --- a/tests/pw/tests/e2e/order-min-max/min-max-01.spec.ts +++ b/tests/pw/tests/e2e/order-min-max/min-max-01.spec.ts @@ -1,32 +1,147 @@ -import { LoginPage } from '@pages/loginPage'; -import DokanModulesPage from '@pages/wp-admin/dokan/settings/modules.page'; -import test, { expect } from '@playwright/test'; +import test, { BrowserContext, expect, Page } from '@playwright/test'; +import { ApiUtils } from '@utils/apiUtils'; +import { payloads } from '@utils/payloads'; +import { data } from '@utils/testData'; -import 'dotenv/config'; -const { ADMIN, ADMIN_PASSWORD } = process.env; +import VendorDashboardSidebarPage from '@pages/frontend/vendor-dashboard/common/vendor-sidebar.page'; +import VendorProductListPage from '@pages/frontend/vendor-dashboard/products/products-list.page'; +import VendorProductAddEditPage from '@pages/frontend/vendor-dashboard/products/product-add-edit.page'; +import ShopPage from '@pages/frontend/shop/shop.page'; +import SingleProductPage from '@pages/frontend/shop/single-product.page'; +import VendorStoreSettingsPage from '@pages/frontend/vendor-dashboard/settings/store/vendor-store.page'; +import { faker } from '@faker-js/faker'; +import MyAccountAuthPage from '@pages/frontend/my-account/auth/my-account-auth.page'; -let baseUrl: string; -let loginPage: LoginPage; +let api: ApiUtils; +let productName: string; +let vendorId: string; +let storeName: string; +let storeSettingsPage: VendorStoreSettingsPage; -test.describe('Order Min-Max - Module Activation', () => { - test.beforeEach(async ({ page }, testInfo) => { - loginPage = new LoginPage(page); - baseUrl = testInfo.project.use.baseURL as string; - await page.goto(baseUrl); +let vendorDashboardSidebarPage: VendorDashboardSidebarPage; +let vendorProductListPage: VendorProductListPage; +let vendorProductAddEditPage: VendorProductAddEditPage; +let vendorMyAccountAuthPage: MyAccountAuthPage; +let vendorPage: Page; +let vendorEmail: string; + +let customerPage: Page; +let shopPage: ShopPage; +let singleProductPage: SingleProductPage; +let customerMyAccountAuthPage: MyAccountAuthPage; +let customerEmail: string; + +let vendorBrowserContext: BrowserContext; +let customerBrowserContext: BrowserContext; + +test.describe('Order Min-Max - Single Product Page', () => { + test.beforeEach(async ({ page, request, browser, baseURL }) => { + await page.goto(baseURL as string); + api = new ApiUtils(request); + + // create customer + const customer = await api.createCustomer(payloads.createCustomer(), payloads.adminAuth); + customerEmail = customer[0].email; + + // create vendor + const vendor = await api.createStore(payloads.createStore(), payloads.adminAuth); + vendorId = vendor[0].id; + vendorEmail = vendor[0].email; + storeName = vendor[0]['store_name']; + + // // create product + const productTitle = `Automation Simple Product ${vendorId}${faker.string.alpha(10)}`; + const product = await api.createProduct( + { + name: productTitle, + type: 'simple', + regular_price: '10', + status: 'publish', + post_author: `${vendorId}`, + categories: [{}], + description: '

test description

', + }, + payloads.adminAuth, + ); + + productName = product[0]['name']; + + // vendor + vendorBrowserContext = await browser.newContext(); + vendorPage = await vendorBrowserContext.newPage(); + vendorDashboardSidebarPage = new VendorDashboardSidebarPage(vendorPage); + vendorMyAccountAuthPage = new MyAccountAuthPage(vendorPage); + vendorProductListPage = new VendorProductListPage(vendorPage); + vendorProductAddEditPage = new VendorProductAddEditPage(vendorPage); + storeSettingsPage = new VendorStoreSettingsPage(vendorPage); + + // customer + customerBrowserContext = await browser.newContext(); + customerPage = await customerBrowserContext.newPage(); + customerMyAccountAuthPage = new MyAccountAuthPage(customerPage); + shopPage = new ShopPage(customerPage); + singleProductPage = new SingleProductPage(customerPage); + + await vendorPage.goto(data.subUrls.frontend.vDashboard.dashboard); + await vendorMyAccountAuthPage.enterUsername(vendorEmail); + await vendorMyAccountAuthPage.enterPassword(process.env.USER_PASSWORD); + await vendorMyAccountAuthPage.clickOnLoginButton(); + + await customerPage.goto(data.subUrls.frontend.myAccount); + await customerMyAccountAuthPage.enterUsername(customerEmail); + await customerMyAccountAuthPage.enterPassword(process.env.USER_PASSWORD); + await customerMyAccountAuthPage.clickOnLoginButton(); }); - test('Admin is able to enable min-max feature from modules page', { tag: ['@lite', '@admin'] }, async ({ page }) => { - let modulesPage = new DokanModulesPage(page); + test.afterEach(async () => { + await vendorBrowserContext.close(); + await customerBrowserContext.close(); + }); + + test('Adding more product than max quantity limit displays error in single product page', { tag: ['@admin'] }, async () => { + await vendorDashboardSidebarPage.clickOnProductsTab(); + await vendorProductListPage.clickOnProductWithTitle(productName); + + const maxQuantity = '2'; + + await vendorProductAddEditPage.enterSimpleProductMaxQty(maxQuantity); + await vendorProductAddEditPage.selectProductStatus('publish'); + await vendorProductAddEditPage.clickOnSaveProduct(); + + await customerPage.goto(data.subUrls.frontend.shop); + await shopPage.clickOnProductWithTitle(productName); + await singleProductPage.clickOnAddToCartButton(); + await singleProductPage.clickOnAddToCartButton(); + await singleProductPage.clickOnAddToCartButton(); + + const errorMessage = await singleProductPage.errorMessageElement().allInnerTexts(); + const expectedErrorMessage = `Maximum allowed quantity for ${productName} is ${maxQuantity}.`; + + expect(errorMessage[0]).toEqual(expectedErrorMessage); + }); + + test('Error displayed in single product page if added product exceeds maximum allowed amount', { tag: ['@admin'] }, async () => { + await vendorDashboardSidebarPage.goto(data.subUrls.frontend.vDashboard.products); + await vendorProductListPage.clickOnProductWithTitle(productName); + + await vendorProductAddEditPage.selectProductStatus('publish'); + await vendorProductAddEditPage.clickOnSaveProduct(); + + const maxAmount = '20'; + + await vendorDashboardSidebarPage.clickOnSettingsTab(); + await storeSettingsPage.enterMaximumOrderAmount(maxAmount); + await storeSettingsPage.clickOnUpdateSettingsButton(); - await loginPage.adminLogin({ username: ADMIN, password: ADMIN_PASSWORD }); - await page.goto(baseUrl + '/wp-admin/admin.php?page=dokan#/modules'); - await modulesPage.searchFor('Min Max Quantities'); - await modulesPage.clickOnModuleToggleButton('Min Max Quantities'); - await modulesPage.clickOnActiveModulesTab(); + await customerPage.goto(data.subUrls.frontend.shop); + await shopPage.clickOnProductWithTitle(productName); + await singleProductPage.clickOnAddToCartButton(); + await singleProductPage.clickOnAddToCartButton(); + await singleProductPage.clickOnAddToCartButton(); - await page.waitForTimeout(2000); - const titleList = await modulesPage.moduleTitle().allInnerTexts(); + const errorMessage = await singleProductPage.errorMessageElement().allInnerTexts(); + const expectedErrorMessage = `Maximum allowed cart amount for ${storeName} is $${maxAmount}.00. You currently have $20.00 in cart.`; - expect(titleList.includes('Min Max Quantities')).toEqual(true); + expect(errorMessage[0]).toEqual(expectedErrorMessage); }); }); diff --git a/tests/pw/tests/e2e/order-min-max/min-max-02.spec.ts b/tests/pw/tests/e2e/order-min-max/min-max-02.spec.ts index 031ffbb81a..b5f34b5bcb 100644 --- a/tests/pw/tests/e2e/order-min-max/min-max-02.spec.ts +++ b/tests/pw/tests/e2e/order-min-max/min-max-02.spec.ts @@ -1,44 +1,46 @@ -import test, { Browser, chromium, expect, Page } from '@playwright/test'; +import test, { BrowserContext, expect, Page } from '@playwright/test'; import { ApiUtils } from '@utils/apiUtils'; import { payloads } from '@utils/payloads'; -import randomstring from 'randomstring'; +import { data } from '@utils/testData'; -import 'dotenv/config'; import VendorDashboardSidebarPage from '@pages/frontend/vendor-dashboard/common/vendor-sidebar.page'; -import MyAccountAuthPage from '@pages/frontend/my-account/auth/my-account-auth.page'; import VendorProductListPage from '@pages/frontend/vendor-dashboard/products/products-list.page'; import VendorProductAddEditPage from '@pages/frontend/vendor-dashboard/products/product-add-edit.page'; import ShopPage from '@pages/frontend/shop/shop.page'; import SingleProductPage from '@pages/frontend/shop/single-product.page'; import VendorStoreSettingsPage from '@pages/frontend/vendor-dashboard/settings/store/vendor-store.page'; +import CartPage from '@pages/frontend/cart.page'; +import StorefrontMainMenu from '@pages/frontend/navigation/main-menu.page'; +import { faker } from '@faker-js/faker'; +import MyAccountAuthPage from '@pages/frontend/my-account/auth/my-account-auth.page'; -let baseUrl: string; let api: ApiUtils; let productName: string; -let customerEmail: string; let vendorId: string; -let vendorEmail: string; let storeName: string; let storeSettingsPage: VendorStoreSettingsPage; let vendorDashboardSidebarPage: VendorDashboardSidebarPage; -let vendorMyAccountAuthPage: MyAccountAuthPage; let vendorProductListPage: VendorProductListPage; let vendorProductAddEditPage: VendorProductAddEditPage; +let vendorMyAccountAuthPage: MyAccountAuthPage; let vendorPage: Page; +let vendorEmail: string; let customerPage: Page; let customerMyAccountAuthPage: MyAccountAuthPage; let shopPage: ShopPage; let singleProductPage: SingleProductPage; +let customerCartPage: CartPage; +let storefrontMainMenu: StorefrontMainMenu; +let customerEmail: string; -let vendorBrowser: Browser; -let customerBrowser: Browser; +let vendorBrowserContext: BrowserContext; +let customerBrowserContext: BrowserContext; -test.describe('Order Min-Max - Single Product Page', () => { - test.beforeEach(async ({ page, request }, testInfo) => { - baseUrl = testInfo.project.use.baseURL as string; - await page.goto(baseUrl); +test.describe('Order Min-Max - Cart Page', () => { + test.beforeEach(async ({ page, request, browser, baseURL }) => { + await page.goto(baseURL as string); api = new ApiUtils(request); // create customer @@ -52,10 +54,10 @@ test.describe('Order Min-Max - Single Product Page', () => { storeName = vendor[0]['store_name']; // // create product - const productTitle = `Automation Simple Product ${vendorId}${randomstring.generate(5)}`; + const title = `Automation Simple Product ${vendorId}${faker.string.alpha(10)}`; const product = await api.createProduct( { - name: productTitle, + name: title, type: 'simple', regular_price: '10', status: 'publish', @@ -69,83 +71,131 @@ test.describe('Order Min-Max - Single Product Page', () => { productName = product[0]['name']; // vendor - vendorBrowser = await chromium.launch(); - vendorPage = await vendorBrowser.newPage(); + vendorBrowserContext = await browser.newContext(); + vendorPage = await vendorBrowserContext.newPage(); + vendorDashboardSidebarPage = new VendorDashboardSidebarPage(vendorPage); - vendorMyAccountAuthPage = new MyAccountAuthPage(vendorPage); vendorProductListPage = new VendorProductListPage(vendorPage); vendorProductAddEditPage = new VendorProductAddEditPage(vendorPage); + vendorMyAccountAuthPage = new MyAccountAuthPage(vendorPage); storeSettingsPage = new VendorStoreSettingsPage(vendorPage); // customer - customerBrowser = await chromium.launch(); - customerPage = await customerBrowser.newPage(); - customerMyAccountAuthPage = new MyAccountAuthPage(customerPage); + customerBrowserContext = await browser.newContext(); + customerPage = await customerBrowserContext.newPage(); shopPage = new ShopPage(customerPage); + customerMyAccountAuthPage = new MyAccountAuthPage(customerPage); singleProductPage = new SingleProductPage(customerPage); + customerCartPage = new CartPage(customerPage); + storefrontMainMenu = new StorefrontMainMenu(customerPage); - // vendor login - await vendorPage.goto(baseUrl + '/dashboard/'); + await vendorPage.goto(data.subUrls.frontend.vDashboard.dashboard); await vendorMyAccountAuthPage.enterUsername(vendorEmail); await vendorMyAccountAuthPage.enterPassword(process.env.USER_PASSWORD); await vendorMyAccountAuthPage.clickOnLoginButton(); - // customer login - await customerPage.goto(baseUrl + '/my-account/'); + await customerPage.goto(data.subUrls.frontend.myAccount); await customerMyAccountAuthPage.enterUsername(customerEmail); await customerMyAccountAuthPage.enterPassword(process.env.USER_PASSWORD); await customerMyAccountAuthPage.clickOnLoginButton(); }); test.afterEach(async () => { - await vendorBrowser.close(); - await customerBrowser.close(); + await vendorBrowserContext.close(); + await customerBrowserContext.close(); }); - test('Adding more product than max quantity limit displays error in single product page', { tag: ['@lite', '@admin'] }, async () => { + test('Product quantity should not be more than maximum limit', { tag: ['@admin'] }, async () => { + // vendor await vendorDashboardSidebarPage.clickOnProductsTab(); await vendorProductListPage.clickOnProductWithTitle(productName); + await vendorProductAddEditPage.enterSimpleProductMaxQty('4'); + await vendorProductAddEditPage.selectProductStatus('publish'); + await vendorProductAddEditPage.clickOnSaveProduct(); + + // customer + await customerPage.goto(data.subUrls.frontend.shop); + await shopPage.clickOnProductWithTitle(productName); + await singleProductPage.clickOnAddToCartButton(); + await customerPage.goto(data.subUrls.frontend.cart); + await customerCartPage.enterQuantityValue(productName, '5'); + await customerCartPage.clickOnUpdateCartButton(); + + const quantityErrorMessage = await customerCartPage.quantityErrorElement().textContent(); + const woocommerceError = await customerCartPage.woocommerceErrorMessage().textContent(); - const maxQuantity = '2'; + expect(quantityErrorMessage?.includes(`Maximum 4 allowed`)).toBeTruthy(); + expect(woocommerceError?.includes(`Maximum allowed quantity for ${productName} is 4.`)).toBeTruthy(); + }); - await vendorProductAddEditPage.enterSimpleProductMaxQty(maxQuantity); + test('Product quantity should not be less than minimum limit', { tag: ['@admin'] }, async () => { + // vendor + await vendorDashboardSidebarPage.clickOnProductsTab(); + await vendorProductListPage.clickOnProductWithTitle(productName); + await vendorProductAddEditPage.enterSimpleProductMinQty('3'); await vendorProductAddEditPage.selectProductStatus('publish'); await vendorProductAddEditPage.clickOnSaveProduct(); - await customerPage.goto(baseUrl + '/shop/'); + // customer + await customerPage.goto(data.subUrls.frontend.shop); await shopPage.clickOnProductWithTitle(productName); await singleProductPage.clickOnAddToCartButton(); - await singleProductPage.clickOnAddToCartButton(); - await singleProductPage.clickOnAddToCartButton(); + await customerPage.goto(data.subUrls.frontend.cart); + await customerCartPage.enterQuantityValue(productName, '2'); + await customerCartPage.clickOnUpdateCartButton(); - const errorMessage = await singleProductPage.errorMessageElement().allInnerTexts(); - const expectedErrorMessage = `Maximum allowed quantity for ${productName} is ${maxQuantity}.`; + const quantityErrorMessage = await customerCartPage.quantityErrorElement().textContent(); + const woocommerceError = await customerCartPage.woocommerceErrorMessage().textContent(); - expect(errorMessage[0]).toEqual(expectedErrorMessage); + expect(quantityErrorMessage?.includes(`Minimum 3 required`)).toBeTruthy(); + expect(woocommerceError?.includes(`Minimum required quantity for ${productName} is 3.`)).toBeTruthy(); }); - test('Error displayed in single product page if added product exceeds maximum allowed amount', { tag: ['@lite', '@admin'] }, async () => { + test('Cart total should not be more than maximum amount limit', { tag: ['@admin'] }, async () => { + // vendor await vendorDashboardSidebarPage.clickOnProductsTab(); await vendorProductListPage.clickOnProductWithTitle(productName); - await vendorProductAddEditPage.selectProductStatus('publish'); await vendorProductAddEditPage.clickOnSaveProduct(); - const maxAmount = '20'; - await vendorDashboardSidebarPage.clickOnSettingsTab(); - await storeSettingsPage.enterMaximumOrderAmount(maxAmount); + await storeSettingsPage.enterMaximumOrderAmount('30'); await storeSettingsPage.clickOnUpdateSettingsButton(); - await customerPage.goto(baseUrl + '/shop/'); + // customer + await customerPage.goto(data.subUrls.frontend.shop); await shopPage.clickOnProductWithTitle(productName); await singleProductPage.clickOnAddToCartButton(); + await customerPage.goto(data.subUrls.frontend.cart); + await customerCartPage.enterQuantityValue(productName, '4'); + await customerCartPage.clickOnUpdateCartButton(); + + const woocommerceError = await customerCartPage.woocommerceErrorMessage().textContent(); + + expect(woocommerceError?.trim()).toEqual(`Maximum allowed cart amount for ${storeName} is $30.00. You currently have $40.00 in cart.`); + }); + + test('Cart total should not be less than minimum amount limit', { tag: ['@admin'] }, async () => { + // vendor + await vendorDashboardSidebarPage.clickOnProductsTab(); + await vendorProductListPage.clickOnProductWithTitle(productName); + await vendorProductAddEditPage.selectProductStatus('publish'); + await vendorProductAddEditPage.clickOnSaveProduct(); + + await vendorDashboardSidebarPage.clickOnSettingsTab(); + await storeSettingsPage.enterMinimumOrderAmount('30'); + await storeSettingsPage.clickOnUpdateSettingsButton(); + + // customer + await customerPage.goto(data.subUrls.frontend.shop); + await shopPage.clickOnProductWithTitle(productName); + await singleProductPage.enterQuantityValue(productName, '2'); await singleProductPage.clickOnAddToCartButton(); - await singleProductPage.clickOnAddToCartButton(); + await customerPage.goto(data.subUrls.frontend.cart); + await storefrontMainMenu.clickOnCartContentLink(); - const errorMessage = await singleProductPage.errorMessageElement().allInnerTexts(); - const expectedErrorMessage = `Maximum allowed cart amount for ${storeName} is $${maxAmount}.00. You currently have $20.00 in cart.`; + const woocommerceError = await customerCartPage.woocommerceErrorMessage().textContent(); - expect(errorMessage[0]).toEqual(expectedErrorMessage); + expect(woocommerceError?.trim()).toEqual(`Minimum required cart amount for ${storeName} is $30.00. You currently have $20.00 in cart.`); }); }); diff --git a/tests/pw/tests/e2e/order-min-max/min-max-03.spec.ts b/tests/pw/tests/e2e/order-min-max/min-max-03.spec.ts deleted file mode 100644 index 0e780cf6a6..0000000000 --- a/tests/pw/tests/e2e/order-min-max/min-max-03.spec.ts +++ /dev/null @@ -1,204 +0,0 @@ -import test, { Browser, chromium, expect, Page } from '@playwright/test'; -import { ApiUtils } from '@utils/apiUtils'; -import { payloads } from '@utils/payloads'; -import randomstring from 'randomstring'; - -import 'dotenv/config'; -import VendorDashboardSidebarPage from '@pages/frontend/vendor-dashboard/common/vendor-sidebar.page'; -import MyAccountAuthPage from '@pages/frontend/my-account/auth/my-account-auth.page'; -import VendorProductListPage from '@pages/frontend/vendor-dashboard/products/products-list.page'; -import VendorProductAddEditPage from '@pages/frontend/vendor-dashboard/products/product-add-edit.page'; -import ShopPage from '@pages/frontend/shop/shop.page'; -import SingleProductPage from '@pages/frontend/shop/single-product.page'; -import VendorStoreSettingsPage from '@pages/frontend/vendor-dashboard/settings/store/vendor-store.page'; -import CartPage from '@pages/frontend/cart.page'; -import StorefrontMainMenu from '@pages/frontend/navigation/main-menu.page'; - -let baseUrl: string; -let api: ApiUtils; -let productName: string; -let customerEmail: string; -let vendorId: string; -let vendorEmail: string; -let storeName: string; -let storeSettingsPage: VendorStoreSettingsPage; - -let vendorDashboardSidebarPage: VendorDashboardSidebarPage; -let vendorMyAccountAuthPage: MyAccountAuthPage; -let vendorProductListPage: VendorProductListPage; -let vendorProductAddEditPage: VendorProductAddEditPage; -let vendorPage: Page; - -let customerPage: Page; -let customerMyAccountAuthPage: MyAccountAuthPage; -let shopPage: ShopPage; -let singleProductPage: SingleProductPage; -let cartPage: CartPage; -let storefrontMainMenu: StorefrontMainMenu; - -let vendorBrowser: Browser; -let customerBrowser: Browser; - -test.describe.only('Order Min-Max - Cart Page', () => { - test.beforeEach(async ({ page, request }, testInfo) => { - baseUrl = testInfo.project.use.baseURL as string; - await page.goto(baseUrl); - api = new ApiUtils(request); - - // create customer - const customer = await api.createCustomer(payloads.createCustomer(), payloads.adminAuth); - customerEmail = customer[0].email; - - // create vendor - const vendor = await api.createStore(payloads.createStore(), payloads.adminAuth); - vendorId = vendor[0].id; - vendorEmail = vendor[0].email; - storeName = vendor[0]['store_name']; - - // // create product - const title = `Automation Simple Product ${vendorId}${randomstring.generate(5)}`; - const product = await api.createProduct( - { - name: title, - type: 'simple', - regular_price: '10', - status: 'publish', - post_author: `${vendorId}`, - categories: [{}], - description: '

test description

', - }, - payloads.adminAuth, - ); - - productName = product[0]['name']; - - // vendor - vendorBrowser = await chromium.launch(); - vendorPage = await vendorBrowser.newPage(); - vendorDashboardSidebarPage = new VendorDashboardSidebarPage(vendorPage); - vendorMyAccountAuthPage = new MyAccountAuthPage(vendorPage); - vendorProductListPage = new VendorProductListPage(vendorPage); - vendorProductAddEditPage = new VendorProductAddEditPage(vendorPage); - storeSettingsPage = new VendorStoreSettingsPage(vendorPage); - - // customer - customerBrowser = await chromium.launch(); - customerPage = await customerBrowser.newPage(); - customerMyAccountAuthPage = new MyAccountAuthPage(customerPage); - shopPage = new ShopPage(customerPage); - singleProductPage = new SingleProductPage(customerPage); - cartPage = new CartPage(customerPage); - storefrontMainMenu = new StorefrontMainMenu(customerPage); - - // vendor login - await vendorPage.goto(baseUrl + '/dashboard/'); - await vendorMyAccountAuthPage.enterUsername(vendorEmail); - await vendorMyAccountAuthPage.enterPassword(process.env.USER_PASSWORD); - await vendorMyAccountAuthPage.clickOnLoginButton(); - - // customer login - await customerPage.goto(baseUrl + '/my-account/'); - await customerMyAccountAuthPage.enterUsername(customerEmail); - await customerMyAccountAuthPage.enterPassword(process.env.USER_PASSWORD); - await customerMyAccountAuthPage.clickOnLoginButton(); - }); - - test.afterEach(async () => { - await vendorBrowser.close(); - await customerBrowser.close(); - }); - - test('Product quantity should not be more than maximum limit', { tag: ['@lite', '@admin'] }, async () => { - // vendor - await vendorDashboardSidebarPage.clickOnProductsTab(); - await vendorProductListPage.clickOnProductWithTitle(productName); - await vendorProductAddEditPage.enterSimpleProductMaxQty('4'); - await vendorProductAddEditPage.selectProductStatus('publish'); - await vendorProductAddEditPage.clickOnSaveProduct(); - - // customer - await customerPage.goto(baseUrl + '/shop/'); - await shopPage.clickOnProductWithTitle(productName); - await singleProductPage.clickOnAddToCartButton(); - await customerPage.goto(baseUrl + '/cart/'); - await cartPage.enterQuantityValue(productName, '5'); - await cartPage.clickOnUpdateCartButton(); - - const quantityErrorMessage = await cartPage.quantityErrorElement().textContent(); - const woocommerceError = await cartPage.woocommerceErrorMessage().textContent(); - - expect(quantityErrorMessage?.includes(`Maximum 4 allowed`)).toBeTruthy(); - expect(woocommerceError?.includes(`Maximum allowed quantity for ${productName} is 4.`)).toBeTruthy(); - }); - - test('Product quantity should not be less than minimum limit', { tag: ['@lite', '@admin'] }, async () => { - // vendor - await vendorDashboardSidebarPage.clickOnProductsTab(); - await vendorProductListPage.clickOnProductWithTitle(productName); - await vendorProductAddEditPage.enterSimpleProductMinQty('3'); - await vendorProductAddEditPage.selectProductStatus('publish'); - await vendorProductAddEditPage.clickOnSaveProduct(); - - // customer - await customerPage.goto(baseUrl + '/shop/'); - await shopPage.clickOnProductWithTitle(productName); - await singleProductPage.clickOnAddToCartButton(); - await customerPage.goto(baseUrl + '/cart/'); - await cartPage.enterQuantityValue(productName, '2'); - await cartPage.clickOnUpdateCartButton(); - - const quantityErrorMessage = await cartPage.quantityErrorElement().textContent(); - const woocommerceError = await cartPage.woocommerceErrorMessage().textContent(); - - expect(quantityErrorMessage?.includes(`Minimum 3 required`)).toBeTruthy(); - expect(woocommerceError?.includes(`Minimum required quantity for ${productName} is 3.`)).toBeTruthy(); - }); - - test('Cart total should not be more than maximum amount limit', { tag: ['@lite', '@admin'] }, async () => { - // vendor - await vendorDashboardSidebarPage.clickOnProductsTab(); - await vendorProductListPage.clickOnProductWithTitle(productName); - await vendorProductAddEditPage.selectProductStatus('publish'); - await vendorProductAddEditPage.clickOnSaveProduct(); - - await vendorDashboardSidebarPage.clickOnSettingsTab(); - await storeSettingsPage.enterMaximumOrderAmount('30'); - await storeSettingsPage.clickOnUpdateSettingsButton(); - - // customer - await customerPage.goto(baseUrl + '/shop/'); - await shopPage.clickOnProductWithTitle(productName); - await singleProductPage.clickOnAddToCartButton(); - await customerPage.goto(baseUrl + '/cart/'); - await cartPage.enterQuantityValue(productName, '4'); - await cartPage.clickOnUpdateCartButton(); - - const woocommerceError = await cartPage.woocommerceErrorMessage().textContent(); - - expect(woocommerceError?.trim()).toEqual(`Maximum allowed cart amount for ${storeName} is $30.00. You currently have $40.00 in cart.`); - }); - - test.only('Cart total should not be less than minimum amount limit', { tag: ['@lite', '@admin'] }, async () => { - // vendor - await vendorDashboardSidebarPage.clickOnProductsTab(); - await vendorProductListPage.clickOnProductWithTitle(productName); - await vendorProductAddEditPage.selectProductStatus('publish'); - await vendorProductAddEditPage.clickOnSaveProduct(); - - await vendorDashboardSidebarPage.clickOnSettingsTab(); - await storeSettingsPage.enterMinimumOrderAmount('30'); - await storeSettingsPage.clickOnUpdateSettingsButton(); - - // customer - await customerPage.goto(baseUrl + '/shop/'); - await shopPage.clickOnProductWithTitle(productName); - await singleProductPage.enterQuantityValue(productName, '2'); - await singleProductPage.clickOnAddToCartButton(); - await customerPage.goto(baseUrl + '/cart/'); - await storefrontMainMenu.clickOnCartContentLink(); - - const woocommerceError = await cartPage.woocommerceErrorMessage().textContent(); - - expect(woocommerceError?.trim()).toEqual(`Minimum required cart amount for ${storeName} is $30.00. You currently have $20.00 in cart.`); - }); -}); 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 10/10] 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(); } }