Commit 3980628311a for woocommerce

commit 3980628311ae639207346a313e409116499a2594
Author: Vlad Olaru <vlad.olaru@automattic.com>
Date:   Fri Sep 18 20:37:52 2026 +0300

    [tests] Locate Add to Cart without the translated label in Blocks E2E (#68875)

    test(blocks): Locate Add to Cart without the translated label

    The Blocks E2E helper found the Add to Cart control by its accessible
    name, `Add to cart: "<product>"`. That string comes from
    WC_Product_Simple::add_to_cart_description(), a PHP __() call, so it is
    translated like any other.

    cart-checkout-block-translations.shopper.block_theme.spec.ts switches
    the site to nl_NL before adding to the cart. Where WooCommerce has a
    Dutch language pack the label renders as "Toevoegen aan winkelwagen",
    the English locator cannot match, and both translation specs time out.

    CI does not see this. The seed installs only core translations, via
    `wp language core install nl_NL`, so a fresh environment has no Dutch
    WooCommerce strings. A long-lived local environment acquires the plugin
    pack through WordPress's automatic translation updates, and the specs
    start failing there while CI stays green.

    Match the product by its title instead. Titles are content, so they are
    not translated. The match is on the title heading rather than any
    descendant text, so a product cannot be selected by text its card
    repeats, such as the button's own label, and it is exact, so "Beanie"
    does not also select "Beanie with Logo". The control is still found by
    class, since it is a button in blocks and a link in the legacy
    template.

    Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>

diff --git a/plugins/woocommerce/changelog/fix-blocks-e2e-add-to-cart-locale-locator b/plugins/woocommerce/changelog/fix-blocks-e2e-add-to-cart-locale-locator
new file mode 100644
index 00000000000..cda81d7c751
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-blocks-e2e-add-to-cart-locale-locator
@@ -0,0 +1,3 @@
+Significance: patch
+Type: dev
+Comment: Locate the Add to Cart control in the Blocks E2E helper by product title and class instead of its translated accessible name, so the cart and checkout translation specs pass on environments that have the WooCommerce language pack installed. E2E test utility 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 6c551e7ac37..168a0514056 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
@@ -124,10 +124,23 @@ export class FrontendUtils {
 		const { waitForCartRequests } = this.trackCartRequests();

 		if ( itemName !== '' ) {
-			// We can't use `getByRole()` here because the Add to Cart button
-			// might be a button (in blocks) or a link (in the legacy template).
+			// The button's accessible name is translated, so matching on it
+			// breaks whenever the site runs in another language. Match the
+			// product by its title, which is content and stays as authored, and
+			// click the control by class, since it is a button in blocks and a
+			// link in the legacy template. Match the heading rather than any
+			// descendant text, so a product cannot be selected by text the
+			// card repeats, and keep it exact, or "Beanie" also selects
+			// "Beanie with Logo".
 			await this.page
-				.getByLabel( `Add to cart: “${ itemName }”` )
+				.locator( 'li.product' )
+				.filter( {
+					has: this.page.getByRole( 'heading', {
+						name: itemName,
+						exact: true,
+					} ),
+				} )
+				.locator( '.add_to_cart_button' )
 				.click();
 		} else {
 			await this.page.click( 'text=Add to cart' );