Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Case :: Order Min Max #2367

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
44 changes: 44 additions & 0 deletions tests/pw/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions tests/pw/pages/frontend/cart.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { BasePage } from '@pages/basePage';

export default class CartPage extends BasePage {
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.page.locator(`//div[@class="quantity"]/label[contains(text(), "${productTitle}")]/following-sibling::input`).fill(quantityValue);
}

async clickOnUpdateCartButton() {
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();
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locators are already defined in pages/selectors. Add new locators there if they are not already included. Using multiple files solely for locators can unnecessarily complicate the project.

15 changes: 15 additions & 0 deletions tests/pw/pages/frontend/my-account/auth/my-account-auth.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { BasePage } from '@pages/basePage';

export default class MyAccountAuthPage extends BasePage {
async enterUsername(username: string) {
await this.page.locator('#username').fill(username);
}

async enterPassword(password: string) {
await this.page.locator('#password').fill(password);
}

async clickOnLoginButton() {
await this.page.locator('//button[@name="login"]').click();
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of creating a class with already implemented methods. use login methods from the LoginPage class

7 changes: 7 additions & 0 deletions tests/pw/pages/frontend/my-orders/all-my-orders.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { BasePage } from '@pages/basePage';

export default class AllMyOrdersPage extends BasePage {
async clickOnViewButtonByOrderId(orderId: string) {
await this.page.locator(`//td[@class="order-number"]/a[contains(text(), "${orderId}")]/../following-sibling::td[5]/a`).click();
}
}
15 changes: 15 additions & 0 deletions tests/pw/pages/frontend/my-orders/customer-order-details.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { BasePage } from '@pages/basePage';

export default class CustomerOrderDetailsPage extends BasePage {
trackingStatusByShipmentNumber(shipmentNumber: string) {
return this.page.locator(`//h4[@class="shippments-tracking-title"]/strong[text()="Shipment ${shipmentNumber} "]/../../div[1]/p/strong`);
}

async markOrderAsReceived(shipmentNumber: string) {
await this.page.locator(`//h4[@class="shippments-tracking-title"]/strong[text()="Shipment ${shipmentNumber} "]/../../div[1]/strong[@class="customer-status"]`).click();
}

async clickOnDialogBoxOkButton() {
await this.page.locator('//div[@role="dialog"]/div[6]/button[text()="OK"]').click();
}
}
7 changes: 7 additions & 0 deletions tests/pw/pages/frontend/navigation/main-menu.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { BasePage } from '@pages/basePage';

export default class StorefrontMainMenu extends BasePage {
async clickOnCartContentLink() {
await this.page.locator('.cart-contents').click();
}
}
7 changes: 7 additions & 0 deletions tests/pw/pages/frontend/shop/shop.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { BasePage } from '@pages/basePage';

export default class ShopPage extends BasePage {
async clickOnProductWithTitle(productTitle: string) {
await this.page.locator('.woocommerce-loop-product__title').getByText(productTitle).click();
}
}
15 changes: 15 additions & 0 deletions tests/pw/pages/frontend/shop/single-product.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { BasePage } from '@pages/basePage';

export default class SingleProductPage extends BasePage {
errorMessageElement() {
return this.page.locator('//ul[@class="woocommerce-error"]/li');
}

async enterQuantityValue(productTitle: string, quantityValue: string) {
await this.page.locator(`//div[@class="quantity"]/label[contains(text(), "${productTitle}")]/following-sibling::input`).fill(quantityValue);
}

async clickOnAddToCartButton() {
await this.page.locator('.single_add_to_cart_button').click();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { BasePage } from '@pages/basePage';

export default class VendorDashboardSidebarPage extends BasePage {
sidebarMenu(title: string) {
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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { BasePage } from '@pages/basePage';

export default class VendorAllOrdersPage extends BasePage {
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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { BasePage } from '@pages/basePage';

export default class VendorEditOrderPage extends BasePage {
async clickOnCreateNewShipmentButton() {
await this.page.locator('#create-tracking-status-action').click();
}

async clickOnShipmentItemCheckboxByIndex(itemNumber: string) {
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.page.locator('#shipment-status').selectOption(status);
}

async selectShippingProvider(providerName: string) {
await this.page.locator('#shipping_status_provider').selectOption(providerName);
}

async enterShippingDate(date: string) {
await this.page.locator('#shipped_status_date').fill(date);
}

async enterShippingTrackingNumber(trackingNumber: string) {
await this.page.locator('#tracking_status_number').fill(trackingNumber);
}

async clickOnCreateShipmentButton() {
await this.page.locator('#add-tracking-status-details').click();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { BasePage } from '@pages/basePage';

export default class VendorProductAddEditPage extends BasePage {
async enterSimpleProductMinQty(quantity: string) {
await this.page.locator('#min_quantity').fill(quantity);
}

async enterSimpleProductMaxQty(quantity: string) {
await this.page.locator('#max_quantity').fill(quantity);
}

async selectProductStatus(status: 'publish' | 'draft' | 'pending') {
await this.page.locator('#post_status').selectOption(status);
}

async clickOnSaveProduct() {
await this.page.locator('#publish').click();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { BasePage } from '@pages/basePage';

export default class VendorProductListPage extends BasePage {
productTitle() {
return this.page.locator(`//td[@data-title="Name"]/strong/a`);
}

async clickOnProductWithTitle(productTitle: string) {
await this.productTitle().getByText(productTitle).click();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { BasePage } from '@pages/basePage';

export default class VendorStoreSettingsPage extends BasePage {
async enterMinimumOrderAmount(amount: string) {
await this.page.locator('#min_amount_to_order').fill(amount);
}

async enterMaximumOrderAmount(amount: string) {
await this.page.locator('#max_amount_to_order').fill(amount);
}

async clickOnUpdateSettingsButton() {
await this.page.locator(`//input[@name="dokan_update_store_settings"]`).click();
}
}
15 changes: 15 additions & 0 deletions tests/pw/pages/wp-admin/common/sidebar.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { BasePage } from '@pages/basePage';

export default class WpAdminSidebar extends BasePage {
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();
}
}
19 changes: 19 additions & 0 deletions tests/pw/pages/wp-admin/dokan/settings/modules.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { BasePage } from '@pages/basePage';

export default class DokanModulesPage extends BasePage {
moduleTitle() {
return this.page.locator(`//div[@class="module-details"]/h3/a`);
}

async searchFor(searchTerm: string) {
await this.page.locator('//div[@class="search-box"]/input').fill(searchTerm);
}

async clickOnModuleToggleButton(moduleName: string) {
await this.page.locator(`//div[@class="module-details"]/h3/a[contains(text(), "${moduleName}")]/../../following-sibling::div/div[2]/label`).click();
}

async clickOnActiveModulesTab() {
await this.page.locator(`//div[@class="module-filter-left"]/ul/li[2]/a`).click();
}
}
33 changes: 33 additions & 0 deletions tests/pw/pages/wp-admin/dokan/settings/shipping-status.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { BasePage } from '@pages/basePage';

export default class DokanShippingStatusPage extends BasePage {
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type of method should be in helpers or Basepage class.

}
Comment on lines +4 to +16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but consider optimizing the method.

The method is correctly implemented and should work as expected. However, it could be optimized by using a more specific XPath selector to find the element with the given status directly, instead of looping through all the elements.

Apply this diff to optimize the method:

-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;
-}
+async shippingStatusItem(status: string) {
+    return this.page.locator(`//ul[@class="dokan-settings-repeatable-list"]/li[contains(., "${status}")]`);
+}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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;
}
async shippingStatusItem(status: string) {
return this.page.locator(`//ul[@class="dokan-settings-repeatable-list"]/li[contains(., "${status}")]`);
}


async clickOnShippingStatusTab() {
await this.page.locator('//div[@class="nav-title"][text()="Shipping Status"]').click();
}

async clickOnAllowShipmentTrackingCheckbox() {
await this.page.locator('(//p/../following-sibling::div/label/label)[1]').click();
}

async clickOnAllowMarkAsReceivedCheckbox() {
await this.page.locator('(//p/../following-sibling::div/label/label)[2]').click();
}

async clickOnSaveChangesButton() {
await this.page.locator('#submit').click();
}
}
7 changes: 7 additions & 0 deletions tests/pw/pages/wp-admin/products/all-products.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { BasePage } from '@pages/basePage';

export default class AllProductsPage extends BasePage {
async clickOnProductTitleById(productId: string) {
await this.page.locator(`//tr[@id="post-${productId}"]/td[2]/strong/a`).click();
}
}
7 changes: 7 additions & 0 deletions tests/pw/pages/wp-admin/products/edit-product.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { BasePage } from '@pages/basePage';

export default class EditProductPage extends BasePage {
async clickOnPublishButton() {
await this.page.locator('#publish').click();
}
}
Loading
Loading