Commit f5150b2341a for woocommerce
commit f5150b2341a5bd9e192649916507e260bedd6834
Author: Adrian Moldovan <3854374+adimoldovan@users.noreply.github.com>
Date: Fri Nov 20 14:18:33 2026 +0200
Run Blocks e2e specs that place orders in parallel (#71136)
diff --git a/plugins/woocommerce/changelog/testops-324-blocks-e2e-parallel-place-orders b/plugins/woocommerce/changelog/testops-324-blocks-e2e-parallel-place-orders
new file mode 100644
index 00000000000..41ea18f0269
--- /dev/null
+++ b/plugins/woocommerce/changelog/testops-324-blocks-e2e-parallel-place-orders
@@ -0,0 +1,3 @@
+Significance: patch
+Type: dev
+Comment: Run five Blocks e2e specs that place orders in the parallel pool; no production change.
diff --git a/plugins/woocommerce/tests/e2e/playwright.config.ts b/plugins/woocommerce/tests/e2e/playwright.config.ts
index af39bb403a3..8ab9277010b 100644
--- a/plugins/woocommerce/tests/e2e/playwright.config.ts
+++ b/plugins/woocommerce/tests/e2e/playwright.config.ts
@@ -244,15 +244,10 @@ const blocksSerialSpecs = [
// stops working.
'**/tests/blocks/templates/shop-page.block_theme.spec.ts',
- // Place orders, which change the Best Sellers ranking. Some also add to the
- // cart as the admin user, whose cart all workers share.
- '**/tests/blocks/cart/cart-checkout-block-coupons.shopper.block_theme.spec.ts',
- '**/tests/blocks/checkout/additional-fields.guest-shopper.block_theme.spec.ts',
- '**/tests/blocks/checkout/additional-fields.merchant.block_theme.spec.ts',
- '**/tests/blocks/checkout/additional-fields.shopper.block_theme.spec.ts',
- '**/tests/blocks/checkout/checkout-block-locale-hide-country.block_theme.spec.ts',
-
- // Create or edit products and categories that catalog specs count.
+ // Creates a visible $10 product with limited stock, which the Product
+ // Collection block needs to show it. While it exists, it changes product
+ // counts that catalog specs check, such as the single product under $10 in
+ // `inspector-controls`.
'**/tests/blocks/product-collection/product-collection-errors.block_theme.spec.ts',
];
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/cart/cart-checkout-block-coupons.shopper.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/cart/cart-checkout-block-coupons.shopper.block_theme.spec.ts
index 641ef4cb9c2..3d9e2fab4b9 100644
--- a/plugins/woocommerce/tests/e2e/tests/blocks/cart/cart-checkout-block-coupons.shopper.block_theme.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/cart/cart-checkout-block-coupons.shopper.block_theme.spec.ts
@@ -1,12 +1,12 @@
/**
* External dependencies
*/
-import { expect, test as base, wpCLI } from '@woocommerce/e2e-utils';
+import { randomUUID } from 'crypto';
+import { expect, test as base, guestFile } from '@woocommerce/e2e-utils';
/**
* Internal dependencies
*/
-import { REGULAR_PRICED_PRODUCT_NAME } from '../checkout/constants';
import { CheckoutPage } from '../checkout/checkout.page';
const test = base.extend< { checkoutPageObject: CheckoutPage } >( {
@@ -19,42 +19,69 @@ const test = base.extend< { checkoutPageObject: CheckoutPage } >( {
} );
test.describe( 'Shopper → Coupon', () => {
- test.beforeEach( async () => {
- await wpCLI(
- 'wc shop_coupon create --code=single-use-coupon --discount_type=percent --amount=10 --usage_limit=1 --user=1'
- );
- } );
-
- test( 'Logged in user can apply single-use coupon and place order', async ( {
+ test.use( { storageState: guestFile } );
+
+ let productId: number;
+ let couponCode: string;
+
+ test.beforeEach(
+ async ( { requestUtils, createHiddenProduct, cleanup } ) => {
+ ( { id: productId } = await createHiddenProduct( {
+ name: 'Coupon test product',
+ regular_price: '20',
+ } ) );
+ couponCode = `single-use-${ randomUUID().slice( 0, 8 ) }`;
+ const { id: couponId } = await requestUtils.rest< { id: number } >(
+ {
+ method: 'POST',
+ path: 'wc/v3/coupons',
+ data: {
+ code: couponCode,
+ discount_type: 'percent',
+ amount: '10',
+ usage_limit: 1,
+ },
+ }
+ );
+ cleanup( () =>
+ requestUtils.rest( {
+ method: 'DELETE',
+ path: `wc/v3/coupons/${ couponId }`,
+ params: { force: true },
+ } )
+ );
+ }
+ );
+
+ test( 'Shopper can apply single-use coupon and place order', async ( {
checkoutPageObject,
frontendUtils,
page,
} ) => {
- await frontendUtils.goToShop();
- await frontendUtils.addToCart( REGULAR_PRICED_PRODUCT_NAME );
+ await page.goto( `/?add-to-cart=${ productId }` );
await frontendUtils.goToCart();
await page.getByRole( 'button', { name: 'Add coupons' } ).click();
- await page.getByLabel( 'Enter code' ).fill( 'single-use-coupon' );
+ await page.getByLabel( 'Enter code' ).fill( couponCode );
await page.getByRole( 'button', { name: 'Apply' } ).click();
await expect(
- page.getByLabel( 'Remove coupon "single-use-coupon"' )
+ page.getByLabel( `Remove coupon "${ couponCode }"` )
).toBeVisible();
- await page.getByLabel( 'Remove coupon "single-use-coupon"' ).click();
+ await page.getByLabel( `Remove coupon "${ couponCode }"` ).click();
await expect(
- page.getByLabel( 'Remove coupon "single-use-coupon"' )
+ page.getByLabel( `Remove coupon "${ couponCode }"` )
).toBeHidden();
await frontendUtils.goToCheckout();
await page.getByRole( 'button', { name: 'Add coupons' } ).click();
- await page.getByLabel( 'Enter code' ).fill( 'single-use-coupon' );
+ await page.getByLabel( 'Enter code' ).fill( couponCode );
await page.getByRole( 'button', { name: 'Apply' } ).click();
await expect(
- page.getByLabel( 'Remove coupon "single-use-coupon"' )
+ page.getByLabel( `Remove coupon "${ couponCode }"` )
).toBeVisible();
await checkoutPageObject.fillInCheckoutWithTestData();
@@ -73,38 +100,36 @@ test.describe( 'Shopper → Coupon', () => {
).toBeVisible();
} );
- test( 'Logged in user cannot apply single-use coupon twice', async ( {
+ test( 'Shopper cannot apply single-use coupon twice', async ( {
checkoutPageObject,
frontendUtils,
page,
} ) => {
- await frontendUtils.goToShop();
- await frontendUtils.addToCart( REGULAR_PRICED_PRODUCT_NAME );
+ await page.goto( `/?add-to-cart=${ productId }` );
await frontendUtils.goToCheckout();
await page.getByRole( 'button', { name: 'Add coupons' } ).click();
- await page.getByLabel( 'Enter code' ).fill( 'single-use-coupon' );
+ await page.getByLabel( 'Enter code' ).fill( couponCode );
await page.getByRole( 'button', { name: 'Apply' } ).click();
await expect(
- page.getByLabel( 'Remove coupon "single-use-coupon"' )
+ page.getByLabel( `Remove coupon "${ couponCode }"` )
).toBeVisible();
await checkoutPageObject.fillInCheckoutWithTestData();
await checkoutPageObject.placeOrder();
await frontendUtils.emptyCart();
- await frontendUtils.goToShop();
- await frontendUtils.addToCart( REGULAR_PRICED_PRODUCT_NAME );
+ await page.goto( `/?add-to-cart=${ productId }` );
await frontendUtils.goToCheckout();
await page.getByRole( 'button', { name: 'Add coupons' } ).click();
- await page.getByLabel( 'Enter code' ).fill( 'single-use-coupon' );
+ await page.getByLabel( 'Enter code' ).fill( couponCode );
await page.getByRole( 'button', { name: 'Apply' } ).click();
await expect(
page.getByText(
- 'Usage limit for coupon "SINGLE-USE-COUPON" has been reached.'
+ `Usage limit for coupon "${ couponCode.toUpperCase() }" has been reached.`
)
).toBeVisible();
} );
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/checkout/additional-fields.guest-shopper.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/checkout/additional-fields.guest-shopper.block_theme.spec.ts
index 7995cbad231..f016c84b1ca 100644
--- a/plugins/woocommerce/tests/e2e/tests/blocks/checkout/additional-fields.guest-shopper.block_theme.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/checkout/additional-fields.guest-shopper.block_theme.spec.ts
@@ -11,7 +11,6 @@ import {
/**
* Internal dependencies
*/
-import { REGULAR_PRICED_PRODUCT_NAME } from './constants';
import { CheckoutPage } from './checkout.page';
const test = base.extend< { checkoutPageObject: CheckoutPage } >( {
@@ -35,9 +34,14 @@ test.describe( 'Shopper → Additional Checkout Fields', () => {
test( 'Shopper can see an error message when a required field is not filled in the checkout form', async ( {
checkoutPageObject,
frontendUtils,
+ page,
+ createHiddenProduct,
} ) => {
- await frontendUtils.goToShop();
- await frontendUtils.addToCart( REGULAR_PRICED_PRODUCT_NAME );
+ const { id: productId } = await createHiddenProduct( {
+ name: 'Additional fields product',
+ regular_price: '20',
+ } );
+ await page.goto( `/?add-to-cart=${ productId }` );
await frontendUtils.goToCheckout();
await checkoutPageObject.editShippingDetails();
@@ -125,9 +129,14 @@ test.describe( 'Shopper → Additional Checkout Fields', () => {
test( 'Shopper can fill in the checkout form with additional fields and can have different value for same field in shipping and billing address', async ( {
checkoutPageObject,
frontendUtils,
+ page,
+ createHiddenProduct,
} ) => {
- await frontendUtils.goToShop();
- await frontendUtils.addToCart( REGULAR_PRICED_PRODUCT_NAME );
+ const { id: productId } = await createHiddenProduct( {
+ name: 'Additional fields product',
+ regular_price: '20',
+ } );
+ await page.goto( `/?add-to-cart=${ productId }` );
await frontendUtils.goToCheckout();
await checkoutPageObject.unsyncBillingWithShipping();
@@ -212,8 +221,7 @@ test.describe( 'Shopper → Additional Checkout Fields', () => {
).toBe( true );
await frontendUtils.emptyCart();
- await frontendUtils.goToShop();
- await frontendUtils.addToCart( REGULAR_PRICED_PRODUCT_NAME );
+ await page.goto( `/?add-to-cart=${ productId }` );
await frontendUtils.goToCheckout();
await checkoutPageObject.editShippingDetails();
@@ -306,9 +314,14 @@ test.describe( 'Shopper → Additional Checkout Fields', () => {
test( 'Fields with JSON schema validation show appropriate error messages', async ( {
checkoutPageObject,
frontendUtils,
+ page,
+ createHiddenProduct,
} ) => {
- await frontendUtils.goToShop();
- await frontendUtils.addToCart( REGULAR_PRICED_PRODUCT_NAME );
+ const { id: productId } = await createHiddenProduct( {
+ name: 'Additional fields product',
+ regular_price: '20',
+ } );
+ await page.goto( `/?add-to-cart=${ productId }` );
await frontendUtils.goToCheckout();
await checkoutPageObject.editShippingDetails();
@@ -374,9 +387,14 @@ test.describe( 'Shopper → Additional Checkout Fields', () => {
test( 'Conditional fields are shown/hidden based on cart state', async ( {
checkoutPageObject,
frontendUtils,
+ page,
+ createHiddenProduct,
} ) => {
- await frontendUtils.goToShop();
- await frontendUtils.addToCart( REGULAR_PRICED_PRODUCT_NAME );
+ const { id: productId } = await createHiddenProduct( {
+ name: 'Additional fields product',
+ regular_price: '20',
+ } );
+ await page.goto( `/?add-to-cart=${ productId }` );
await frontendUtils.goToCheckout();
// The shipping insurance field should be hidden by default (cart total < 2000)
@@ -384,8 +402,7 @@ test.describe( 'Shopper → Additional Checkout Fields', () => {
checkoutPageObject.page.getByLabel( 'Add shipping insurance' )
).toBeHidden();
- await frontendUtils.goToShop();
- await frontendUtils.addToCart( REGULAR_PRICED_PRODUCT_NAME );
+ await page.goto( `/?add-to-cart=${ productId }` );
await frontendUtils.goToCheckout();
// The shipping insurance field should now be visible (cart total > 2000)
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/checkout/additional-fields.merchant.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/checkout/additional-fields.merchant.block_theme.spec.ts
index ab2c0063968..78985b620ef 100644
--- a/plugins/woocommerce/tests/e2e/tests/blocks/checkout/additional-fields.merchant.block_theme.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/checkout/additional-fields.merchant.block_theme.spec.ts
@@ -1,35 +1,61 @@
/**
* External dependencies
*/
-import { expect, test as base, enableTestPlugin } from '@woocommerce/e2e-utils';
+import type { Page } from '@playwright/test';
+import {
+ expect,
+ test as base,
+ adminFile,
+ enableTestPlugin,
+ guestFile,
+} from '@woocommerce/e2e-utils';
/**
* Internal dependencies
*/
-import { REGULAR_PRICED_PRODUCT_NAME } from './constants';
import { CheckoutPage } from './checkout.page';
-const test = base.extend< { checkoutPageObject: CheckoutPage } >( {
+const test = base.extend< {
+ checkoutPageObject: CheckoutPage;
+ adminPage: Page;
+} >( {
checkoutPageObject: async ( { page }, use ) => {
const pageObject = new CheckoutPage( {
page,
} );
await use( pageObject );
},
+ // The order is placed as a guest, because all workers share the admin
+ // cart. The merchant views it in a separate admin context.
+ adminPage: async ( { browser }, use ) => {
+ const context = await browser.newContext( {
+ storageState: adminFile,
+ } );
+ await enableTestPlugin( context, 'additional-checkout-fields' );
+ await use( await context.newPage() );
+ await context.close();
+ },
} );
test.describe( 'Merchant → Additional Checkout Fields', () => {
- test.beforeEach( async ( { context, frontendUtils } ) => {
- await enableTestPlugin( context, 'additional-checkout-fields' );
+ test.use( { storageState: guestFile } );
- await frontendUtils.goToShop();
- await frontendUtils.addToCart( REGULAR_PRICED_PRODUCT_NAME );
- await frontendUtils.goToCheckout();
- } );
+ test.beforeEach(
+ async ( { context, page, createHiddenProduct, frontendUtils } ) => {
+ await enableTestPlugin( context, 'additional-checkout-fields' );
+
+ const { id } = await createHiddenProduct( {
+ name: 'Additional fields merchant product',
+ regular_price: '20',
+ } );
+ await page.goto( `/?add-to-cart=${ id }` );
+ await frontendUtils.goToCheckout();
+ }
+ );
test( 'Merchant can see additional fields in the order admin page', async ( {
checkoutPageObject,
- admin,
+ adminPage,
} ) => {
await checkoutPageObject.editShippingDetails();
await checkoutPageObject.unsyncBillingWithShipping();
@@ -108,69 +134,69 @@ test.describe( 'Merchant → Additional Checkout Fields', () => {
await checkoutPageObject.placeOrder();
const orderId = checkoutPageObject.getOrderId();
- await admin.page.goto(
+ await adminPage.goto(
`wp-admin/post.php?post=${ orderId }&action=edit`
);
await expect(
- admin.page.getByText( 'Government ID: 12345', { exact: true } )
+ adminPage.getByText( 'Government ID: 12345', { exact: true } )
).toBeVisible();
await expect(
- admin.page.getByText( 'Confirm government ID: 12345', {
+ adminPage.getByText( 'Confirm government ID: 12345', {
exact: true,
} )
).toBeVisible();
await expect(
- admin.page.getByText( 'Government ID: 54321', { exact: true } )
+ adminPage.getByText( 'Government ID: 54321', { exact: true } )
).toBeVisible();
await expect(
- admin.page.getByText( 'Confirm government ID: 54321', {
+ adminPage.getByText( 'Confirm government ID: 54321', {
exact: true,
} )
).toBeVisible();
await expect(
- admin.page.getByText( 'What is your favourite colour?: Blue' )
+ adminPage.getByText( 'What is your favourite colour?: Blue' )
).toBeVisible();
await expect(
- admin.page.getByText(
+ adminPage.getByText(
'Enter a gift message to include in the package: This is for you!'
)
).toBeVisible();
await expect(
- admin.page.getByText(
+ adminPage.getByText(
'Do you want to subscribe to our newsletter?: Yes'
)
).toBeVisible();
await expect(
- admin.page.getByText(
+ adminPage.getByText(
'Would you like a free gift with your order?: Yes'
)
).toBeVisible();
await expect(
- admin.page.getByText( 'Can a truck fit down your road?: Yes' )
+ adminPage.getByText( 'Can a truck fit down your road?: Yes' )
).toBeVisible();
await expect(
- admin.page.getByText( 'Can a truck fit down your road?: No' )
+ adminPage.getByText( 'Can a truck fit down your road?: No' )
).toBeVisible();
await expect(
- admin.page.getByText( 'How wide is your road?: Wide' )
+ adminPage.getByText( 'How wide is your road?: Wide' )
).toBeVisible();
await expect(
- admin.page.getByText( 'How wide is your road?: Narrow' )
+ adminPage.getByText( 'How wide is your road?: Narrow' )
).toBeVisible();
await expect(
- admin.page.getByText(
+ adminPage.getByText(
'Is this a personal purchase or a business purchase?: Business'
)
).toBeVisible();
await expect(
- admin.page.getByText( 'How did you hear about us?: Other' )
+ adminPage.getByText( 'How did you hear about us?: Other' )
).toBeVisible();
} );
test( 'Merchant can edit custom fields from the order admin page', async ( {
checkoutPageObject,
- admin,
+ adminPage,
} ) => {
await checkoutPageObject.editShippingDetails();
await checkoutPageObject.unsyncBillingWithShipping();
@@ -249,165 +275,165 @@ test.describe( 'Merchant → Additional Checkout Fields', () => {
await checkoutPageObject.placeOrder();
const orderId = checkoutPageObject.getOrderId();
- await admin.page.goto(
+ await adminPage.goto(
`wp-admin/post.php?post=${ orderId }&action=edit`
);
- await admin.page
+ await adminPage
.getByRole( 'heading', { name: 'Billing Edit' } )
.getByRole( 'link' )
.click();
// Change all the billing details
- await admin.page
+ await adminPage
.getByRole( 'textbox', {
name: 'Government ID',
exact: true,
} )
.fill( '99999' );
- await admin.page
+ await adminPage
.getByRole( 'textbox', {
name: 'Confirm government ID',
exact: true,
} )
.fill( '99999' );
- await admin.page
+ await adminPage
.getByRole( 'checkbox', {
name: 'Can a truck fit down your road?',
} )
.check();
// Use Locator here because the select2 box is duplicated in shipping.
- await admin.page
+ await adminPage
.locator(
'[id="\\_wc_billing\\/first-plugin-namespace\\/road-size"]'
)
.selectOption( 'wide' );
// Handle changing the contact fields.
- await admin.page
+ await adminPage
.getByLabel( 'Do you want to subscribe to our newsletter?' )
.uncheck();
- await admin.page
+ await adminPage
.getByLabel( 'Enter a gift message to include in the package' )
.fill( 'Some other message' );
- await admin.page
+ await adminPage
.getByLabel( 'Is this a personal purchase or a business purchase?' )
.selectOption( 'personal' );
- const clickPromise = admin.page
+ const clickPromise = adminPage
.getByRole( 'button', { name: 'Update' } )
.first()
.click();
- const navigationPromise = admin.page.waitForEvent( 'domcontentloaded' );
+ const navigationPromise = adminPage.waitForEvent( 'domcontentloaded' );
// When update is clicked without waiting for DOMContentLoaded the page becomes
// available before click handlers are attached to the shipping edit link.
await Promise.all( [ clickPromise, navigationPromise ] );
- await admin.page
+ await adminPage
.getByRole( 'heading', { name: 'Shipping Edit' } )
.getByRole( 'link' )
.click();
// Change all the shipping details
- await admin.page
+ await adminPage
.getByRole( 'textbox', {
name: 'Government ID',
exact: true,
} )
.fill( '88888' );
- await admin.page
+ await adminPage
.getByRole( 'textbox', {
name: 'Confirm government ID',
exact: true,
} )
.fill( '88888' );
- await admin.page
+ await adminPage
.getByRole( 'checkbox', {
name: 'Can a truck fit down your road?',
} )
.uncheck();
// Use Locator here because the select2 box is duplicated in billing.
- await admin.page
+ await adminPage
.locator(
'[id="\\_wc_shipping\\/first-plugin-namespace\\/road-size"]'
)
.selectOption( 'super-wide' );
// Handle changing the additional information fields.
- await admin.page
+ await adminPage
.getByLabel( 'Would you like a free gift with your order?' )
.uncheck();
- await admin.page
+ await adminPage
.getByLabel( 'What is your favourite colour?' )
.fill( 'Green' );
- await admin.page
+ await adminPage
.getByLabel( 'How did you hear about us?' )
.selectOption( 'google' );
- await admin.page
+ await adminPage
.getByRole( 'button', { name: 'Update' } )
.first()
.click();
- await admin.page.waitForLoadState( 'domcontentloaded' );
+ await adminPage.waitForLoadState( 'domcontentloaded' );
await expect(
- admin.page.getByText( 'Government ID: 88888', { exact: true } )
+ adminPage.getByText( 'Government ID: 88888', { exact: true } )
).toBeVisible();
await expect(
- admin.page.getByText( 'Confirm government ID: 88888', {
+ adminPage.getByText( 'Confirm government ID: 88888', {
exact: true,
} )
).toBeVisible();
await expect(
- admin.page.getByText( 'Government ID: 99999', { exact: true } )
+ adminPage.getByText( 'Government ID: 99999', { exact: true } )
).toBeVisible();
await expect(
- admin.page.getByText( 'Confirm government ID: 99999', {
+ adminPage.getByText( 'Confirm government ID: 99999', {
exact: true,
} )
).toBeVisible();
await expect(
- admin.page.getByText( 'What is your favourite colour?: Green' )
+ adminPage.getByText( 'What is your favourite colour?: Green' )
).toBeVisible();
await expect(
- admin.page.getByText(
+ adminPage.getByText(
'Enter a gift message to include in the package: Some other message'
)
).toBeVisible();
await expect(
- admin.page.getByText(
+ adminPage.getByText(
'Do you want to subscribe to our newsletter?: No'
)
).toBeVisible();
await expect(
- admin.page.getByText(
+ adminPage.getByText(
'Would you like a free gift with your order?: No'
)
).toBeVisible();
await expect(
- admin.page.getByText( 'Can a truck fit down your road?: Yes' )
+ adminPage.getByText( 'Can a truck fit down your road?: Yes' )
).toBeVisible();
await expect(
- admin.page.getByText( 'Can a truck fit down your road?: No' )
+ adminPage.getByText( 'Can a truck fit down your road?: No' )
).toBeVisible();
await expect(
- admin.page.getByText( 'How wide is your road?: Super wide' )
+ adminPage.getByText( 'How wide is your road?: Super wide' )
).toBeVisible();
await expect(
- admin.page.getByText( 'How wide is your road?: Wide' )
+ adminPage.getByText( 'How wide is your road?: Wide' )
).toBeVisible();
await expect(
- admin.page.getByText(
+ adminPage.getByText(
'Is this a personal purchase or a business purchase?: Personal'
)
).toBeVisible();
await expect(
- admin.page.getByText( 'How did you hear about us?: Google' )
+ adminPage.getByText( 'How did you hear about us?: Google' )
).toBeVisible();
} );
} );
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/checkout/additional-fields.shopper.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/checkout/additional-fields.shopper.block_theme.spec.ts
index 55a68e73056..61961f5d8f9 100644
--- a/plugins/woocommerce/tests/e2e/tests/blocks/checkout/additional-fields.shopper.block_theme.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/checkout/additional-fields.shopper.block_theme.spec.ts
@@ -1,17 +1,17 @@
/**
* External dependencies
*/
+import { randomUUID } from 'crypto';
import {
expect,
test as base,
- customerFile,
enableTestPlugin,
+ guestFile,
} from '@woocommerce/e2e-utils';
/**
* Internal dependencies
*/
-import { REGULAR_PRICED_PRODUCT_NAME } from './constants';
import { CheckoutPage } from './checkout.page';
const test = base.extend< { checkoutPageObject: CheckoutPage } >( {
@@ -26,18 +26,51 @@ const test = base.extend< { checkoutPageObject: CheckoutPage } >( {
test.describe( 'Shopper → Additional Checkout Fields', () => {
test.describe( 'Logged in shopper', () => {
- test.use( { storageState: customerFile } );
+ test.use( { storageState: guestFile } );
- test.beforeEach( async ( { context } ) => {
+ // Each test logs in as a new customer. The shared customer's cart and
+ // saved checkout values would carry over between tests, because
+ // `blocks-parallel` does not reset the database.
+ test.beforeEach( async ( { context, page, requestUtils, cleanup } ) => {
await enableTestPlugin( context, 'additional-checkout-fields' );
+
+ const username = `additional-fields-${ randomUUID().slice( 0, 8 ) }`;
+ const password = 'password';
+ const { id } = await requestUtils.rest< { id: number } >( {
+ method: 'POST',
+ path: 'wc/v3/customers',
+ data: {
+ username,
+ password,
+ email: `${ username }@example.com`,
+ },
+ } );
+ cleanup( () =>
+ requestUtils.rest( {
+ method: 'DELETE',
+ path: `wc/v3/customers/${ id }`,
+ params: { force: true },
+ } )
+ );
+
+ const login = await page.request.post( 'wp-login.php', {
+ form: { log: username, pwd: password },
+ } );
+ // A failed login shows the form again instead of redirecting.
+ expect( login.url() ).not.toContain( 'wp-login.php' );
} );
test( 'Shopper can fill in the checkout form with additional fields and can have different value for same field in shipping and billing address', async ( {
checkoutPageObject,
frontendUtils,
+ page,
+ createHiddenProduct,
} ) => {
- await frontendUtils.goToShop();
- await frontendUtils.addToCart( REGULAR_PRICED_PRODUCT_NAME );
+ const { id: productId } = await createHiddenProduct( {
+ name: 'Additional fields product',
+ regular_price: '20',
+ } );
+ await page.goto( `/?add-to-cart=${ productId }` );
await frontendUtils.goToCheckout();
await checkoutPageObject.editShippingDetails();
@@ -121,8 +154,7 @@ test.describe( 'Shopper → Additional Checkout Fields', () => {
).toBe( true );
await frontendUtils.emptyCart();
- await frontendUtils.goToShop();
- await frontendUtils.addToCart( REGULAR_PRICED_PRODUCT_NAME );
+ await page.goto( `/?add-to-cart=${ productId }` );
await frontendUtils.goToCheckout();
await checkoutPageObject.editShippingDetails();
@@ -215,9 +247,14 @@ test.describe( 'Shopper → Additional Checkout Fields', () => {
test( 'Shopper can change the values of fields multiple times and place the order', async ( {
checkoutPageObject,
frontendUtils,
+ page,
+ createHiddenProduct,
} ) => {
- await frontendUtils.goToShop();
- await frontendUtils.addToCart( REGULAR_PRICED_PRODUCT_NAME );
+ const { id: productId } = await createHiddenProduct( {
+ name: 'Additional fields product',
+ regular_price: '20',
+ } );
+ await page.goto( `/?add-to-cart=${ productId }` );
await frontendUtils.goToCheckout();
await checkoutPageObject.editShippingDetails();
@@ -378,9 +415,14 @@ test.describe( 'Shopper → Additional Checkout Fields', () => {
test( 'Shopper can input unsanitized values that become sanitized after checkout', async ( {
checkoutPageObject,
frontendUtils,
+ page,
+ createHiddenProduct,
} ) => {
- await frontendUtils.goToShop();
- await frontendUtils.addToCart( REGULAR_PRICED_PRODUCT_NAME );
+ const { id: productId } = await createHiddenProduct( {
+ name: 'Additional fields product',
+ regular_price: '20',
+ } );
+ await page.goto( `/?add-to-cart=${ productId }` );
await frontendUtils.goToCheckout();
await checkoutPageObject.editShippingDetails();
@@ -464,8 +506,7 @@ test.describe( 'Shopper → Additional Checkout Fields', () => {
).toBe( true );
await frontendUtils.emptyCart();
- await frontendUtils.goToShop();
- await frontendUtils.addToCart( REGULAR_PRICED_PRODUCT_NAME );
+ await page.goto( `/?add-to-cart=${ productId }` );
await frontendUtils.goToCheckout();
await checkoutPageObject.editShippingDetails();
@@ -558,9 +599,14 @@ test.describe( 'Shopper → Additional Checkout Fields', () => {
test( 'Shopper can see server-side validation errors', async ( {
checkoutPageObject,
frontendUtils,
+ page,
+ createHiddenProduct,
} ) => {
- await frontendUtils.goToShop();
- await frontendUtils.addToCart( REGULAR_PRICED_PRODUCT_NAME );
+ const { id: productId } = await createHiddenProduct( {
+ name: 'Additional fields product',
+ regular_price: '20',
+ } );
+ await page.goto( `/?add-to-cart=${ productId }` );
await frontendUtils.goToCheckout();
await checkoutPageObject.editShippingDetails();
@@ -697,9 +743,14 @@ test.describe( 'Shopper → Additional Checkout Fields', () => {
test( 'Shopper can see and edit submitted fields in my account area. Values are also sanitized and validated in my account area.', async ( {
checkoutPageObject,
frontendUtils,
+ page,
+ createHiddenProduct,
} ) => {
- await frontendUtils.goToShop();
- await frontendUtils.addToCart( REGULAR_PRICED_PRODUCT_NAME );
+ const { id: productId } = await createHiddenProduct( {
+ name: 'Additional fields product',
+ regular_price: '20',
+ } );
+ await page.goto( `/?add-to-cart=${ productId }` );
await frontendUtils.goToCheckout();
await checkoutPageObject.editShippingDetails();
@@ -968,9 +1019,14 @@ test.describe( 'Shopper → Additional Checkout Fields', () => {
test( 'Shopper can refresh the page, and not lose any entered data', async ( {
checkoutPageObject,
frontendUtils,
+ page,
+ createHiddenProduct,
} ) => {
- await frontendUtils.goToShop();
- await frontendUtils.addToCart( REGULAR_PRICED_PRODUCT_NAME );
+ const { id: productId } = await createHiddenProduct( {
+ name: 'Additional fields product',
+ regular_price: '20',
+ } );
+ await page.goto( `/?add-to-cart=${ productId }` );
await frontendUtils.goToCheckout();
await checkoutPageObject.editShippingDetails();
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/checkout/checkout-block-locale-hide-country.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/checkout/checkout-block-locale-hide-country.block_theme.spec.ts
index 0a0e23e653a..3c68247bf13 100644
--- a/plugins/woocommerce/tests/e2e/tests/blocks/checkout/checkout-block-locale-hide-country.block_theme.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/checkout/checkout-block-locale-hide-country.block_theme.spec.ts
@@ -11,7 +11,6 @@ import {
/**
* Internal dependencies
*/
-import { SIMPLE_PHYSICAL_PRODUCT_NAME } from './constants';
import { CheckoutPage } from './checkout.page';
const test = base.extend< { checkoutPageObject: CheckoutPage } >( {
@@ -27,18 +26,18 @@ const test = base.extend< { checkoutPageObject: CheckoutPage } >( {
test.describe( 'Checkout Block → Locale hides address fields but not country', () => {
test.use( { storageState: guestFile } );
- test.beforeEach( async ( { context, requestUtils, frontendUtils } ) => {
- await enableTestPlugin( context, 'locale-hide-country' );
- await requestUtils.rest( {
- method: 'PUT',
- path: 'wc/v3/settings/account/woocommerce_enable_guest_checkout',
- data: { value: 'yes' },
- } );
+ test.beforeEach(
+ async ( { context, page, createHiddenProduct, frontendUtils } ) => {
+ await enableTestPlugin( context, 'locale-hide-country' );
- await frontendUtils.goToShop();
- await frontendUtils.addToCart( SIMPLE_PHYSICAL_PRODUCT_NAME );
- await frontendUtils.goToCheckout();
- } );
+ const { id } = await createHiddenProduct( {
+ name: 'Locale hide country product',
+ regular_price: '10',
+ } );
+ await page.goto( `/?add-to-cart=${ id }` );
+ await frontendUtils.goToCheckout();
+ }
+ );
test( 'Country remains visible even when locale tries to hide it', async ( {
page,
diff --git a/plugins/woocommerce/tests/e2e/utils/blocks/test.ts b/plugins/woocommerce/tests/e2e/utils/blocks/test.ts
index 2d040c7652b..9215a48578f 100644
--- a/plugins/woocommerce/tests/e2e/utils/blocks/test.ts
+++ b/plugins/woocommerce/tests/e2e/utils/blocks/test.ts
@@ -139,6 +139,9 @@ const test = base.extend<
sourceProductSlug: string,
options?: { content?: string }
) => Promise< ProductTemplate >;
+ createHiddenProduct: (
+ data: Record< string, unknown >
+ ) => Promise< { id: number } >;
},
{
requestUtils: RequestUtils;
@@ -358,6 +361,66 @@ const test = base.extend<
)
);
},
+ // Creates a product for a test that places orders. Hidden from the catalog
+ // and dated in the past, it stays out of Best Sellers, New Arrivals and
+ // catalog counts. After the test, it deletes the orders for the product,
+ // including checkout drafts, then the product.
+ createHiddenProduct: async ( { requestUtils }, use ) => {
+ const productIds: number[] = [];
+
+ await use( async ( data ) => {
+ const product = await requestUtils.rest< { id: number } >( {
+ method: 'POST',
+ path: 'wc/v3/products',
+ data: {
+ catalog_visibility: 'hidden',
+ date_created: '2020-01-01T00:00:00',
+ ...data,
+ },
+ } );
+ productIds.push( product.id );
+ return product;
+ } );
+
+ const results = await Promise.allSettled(
+ productIds.map( async ( productId ) => {
+ try {
+ // `any` leaves out checkout drafts.
+ const orders = await requestUtils.rest< { id: number }[] >(
+ {
+ path: 'wc/v3/orders',
+ params: {
+ product: productId,
+ status: 'pending,processing,on-hold,completed,cancelled,refunded,failed,checkout-draft',
+ per_page: 100,
+ },
+ }
+ );
+ await Promise.all(
+ orders.map( ( { id } ) =>
+ requestUtils.rest( {
+ method: 'DELETE',
+ path: `wc/v3/orders/${ id }`,
+ params: { force: true },
+ } )
+ )
+ );
+ } finally {
+ await requestUtils.rest( {
+ method: 'DELETE',
+ path: `wc/v3/products/${ productId }`,
+ params: { force: true },
+ } );
+ }
+ } )
+ );
+ for ( const result of results ) {
+ if ( result.status === 'rejected' ) {
+ // eslint-disable-next-line no-console
+ console.warn( 'Test cleanup failed:', result.reason );
+ }
+ }
+ },
requestUtils: [
async ( {}, use, workerInfo ) => {
const requestUtils = await RequestUtils.setup( {