Commit b7b9e8fe6bc for woocommerce
commit b7b9e8fe6bcf929546cd66fcc0cbd6ad56d54ef6
Author: Adrian Moldovan <3854374+adimoldovan@users.noreply.github.com>
Date: Thu Nov 12 16:36:36 2026 +0200
Fix flaky Checkout test in the Page Content Wrapper Blocks E2E spec (#70921)
Wait for the add-to-cart response in the Blocks E2E addToCart()
addToCart() waited for the add-to-cart response only when it got a
product name. Without one, waitForCartRequests() could resolve before
the request started, and the test moved on too early. If /checkout
loaded before the server saved the cart, it saw an empty cart and
redirected to /cart.
This made "Page Content Wrapper › the content of the Checkout page is
correctly rendered in the Checkout template" flaky. Both branches now
wait for the response.
diff --git a/plugins/woocommerce/changelog/fix-e2e-blocks-page-content-wrapper-checkout-flake b/plugins/woocommerce/changelog/fix-e2e-blocks-page-content-wrapper-checkout-flake
new file mode 100644
index 00000000000..2b94c914585
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-e2e-blocks-page-content-wrapper-checkout-flake
@@ -0,0 +1,4 @@
+Significance: patch
+Type: dev
+Comment: Fix a flaky Blocks E2E checkout test; test helper only, no production change.
+
diff --git a/plugins/woocommerce/tests/e2e/utils/blocks/frontend/frontend-utils.page.ts b/plugins/woocommerce/tests/e2e/utils/blocks/frontend/frontend-utils.page.ts
index 59a8cc86cbb..61924317493 100644
--- a/plugins/woocommerce/tests/e2e/utils/blocks/frontend/frontend-utils.page.ts
+++ b/plugins/woocommerce/tests/e2e/utils/blocks/frontend/frontend-utils.page.ts
@@ -123,6 +123,16 @@ export class FrontendUtils {
// Start tracking cart requests before the action
const { waitForCartRequests } = this.trackCartRequests();
+ // The request can start after the click returns, so
+ // waitForCartRequests() alone can resolve before it. A page loaded
+ // before the server saves the cart can see an empty cart.
+ const cartUpdated = this.page.waitForResponse( ( response ) =>
+ [
+ ...STORE_API_CART_WRITE_REQUEST_URLS,
+ 'wc-ajax=add_to_cart',
+ ].some( ( url ) => response.url().includes( url ) )
+ );
+
if ( itemName !== '' ) {
// The button's accessible name is translated, so matching on it
// breaks whenever the site runs in another language. Match the
@@ -132,16 +142,6 @@ export class FrontendUtils {
// descendant text, so a product cannot be selected by text the
// card repeats, and keep it exact, or "Beanie" also selects
// "Beanie with Logo".
- //
- // The request starts after the click returns, so the tracker below
- // alone can resolve before it. A guest gets its session cookie
- // only from this response.
- const cartUpdated = this.page.waitForResponse( ( response ) =>
- [
- ...STORE_API_CART_WRITE_REQUEST_URLS,
- 'wc-ajax=add_to_cart',
- ].some( ( url ) => response.url().includes( url ) )
- );
await this.page
.locator( 'li.product' )
.filter( {
@@ -152,12 +152,12 @@ export class FrontendUtils {
} )
.locator( '.add_to_cart_button' )
.click();
- await cartUpdated;
} else {
await this.page.click( 'text=Add to cart' );
}
+ await cartUpdated;
- // Wait for the cart request triggered by this action to complete
+ // Wait for any other cart requests this action triggered to complete.
// We do it the complex way as there are no visual cues that we can rely on
await waitForCartRequests();
}