Commit 108a6dce55c for woocommerce
commit 108a6dce55c7fd6fe45527a64a15fef98a87b3a7
Author: iris-woocommerce[bot] <282076412+iris-woocommerce[bot]@users.noreply.github.com>
Date: Fri Nov 27 12:39:13 2026 +0000
Blocks e2e: wait for the add-to-cart response in the cart-line identity variation test (#71460)
diff --git a/plugins/woocommerce/changelog/fix-flaky-cart-line-identity-variation-e2e b/plugins/woocommerce/changelog/fix-flaky-cart-line-identity-variation-e2e
new file mode 100644
index 00000000000..97a47fdfe53
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-flaky-cart-line-identity-variation-e2e
@@ -0,0 +1,4 @@
+Significance: patch
+Type: dev
+Comment: Fix flaky cart-line identity e2e test for variation adds; tests only, no production change.
+
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/cart-store/cart-line-identity.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/cart-store/cart-line-identity.block_theme.spec.ts
index c61db94138d..670f9f5fcd6 100644
--- a/plugins/woocommerce/tests/e2e/tests/blocks/cart-store/cart-line-identity.block_theme.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/cart-store/cart-line-identity.block_theme.spec.ts
@@ -284,16 +284,26 @@ test.describe( 'Add to cart respects cart-line identity', () => {
const addToCartButton = addToCartBlock.locator(
'.single_add_to_cart_button'
);
+ // The button text updates optimistically before the Store API
+ // request settles, so wait for the server response before relying
+ // on the cart contents (e.g. navigating to the Cart page).
+ const addToCartAndWaitForResponse = async () => {
+ const batchResponse = page.waitForResponse(
+ '**/wp-json/wc/store/v1/batch**'
+ );
+ await addToCartButton.click();
+ await batchResponse;
+ };
// Select variation V (Blue, Large) and add it: creates V's line.
await colorBlueOption.click();
await sizeLargeOption.click();
await expect( addToCartButton ).not.toHaveClass( /\bdisabled\b/ );
- await addToCartButton.click();
+ await addToCartAndWaitForResponse();
await expect( addToCartButton ).toHaveText( '1 in cart' );
// Add V again: increments V's existing line (no second V line).
- await addToCartButton.click();
+ await addToCartAndWaitForResponse();
await expect( addToCartButton ).toHaveText( '2 in cart' );
// Select a different variation W (Red, Large), not in the cart: the
@@ -302,7 +312,7 @@ test.describe( 'Add to cart respects cart-line identity', () => {
await expect( addToCartButton ).toHaveText( 'Add to cart' );
// Add W: creates a new, separate line for W.
- await addToCartButton.click();
+ await addToCartAndWaitForResponse();
await expect( addToCartButton ).toHaveText( '1 in cart' );
// Persisted cart: V incremented to 2 and W added as a distinct line,