Commit ee1162ae6f8 for woocommerce

commit ee1162ae6f8bb62d968c66881e1d0cfe0cd73040
Author: Vlad Olaru <vlad.olaru@automattic.com>
Date:   Mon Sep 14 11:25:04 2026 +0300

    [tests] Make checkout payment method selectors exact in two retained E2E specs (#68639)

    test(checkout): Make checkout payment method selectors exact

    Both specs pick a payment method by its visible text: getByText( 'Cash
    on delivery' ) in each, and getByText( 'Direct bank transfer' ) in
    checkout.spec.ts. That is a substring match, and a gateway's description
    can contain its own title, in which case the locator matches both the
    label and the description and Playwright fails in strict mode before the
    order is placed. The E2E Blocks seed writes exactly such descriptions:
    bin/blocks/scripts/parallel/payment.sh sets the COD description to "Cash
    on delivery description" and the BACS one to "Direct bank transfer
    description".

    That is not hypothetical. Against a store carrying those settings,
    trunk's own copy of checkout.spec.ts fails with:

        strict mode violation: getByText('Cash on delivery')
        resolved to 2 elements: [trimmed; the PR body has it verbatim]
          1) <label for="payment_method_cod">Cash on delivery </label>
          2) <p>Cash on delivery description</p>

    Make the seven selectors exact: five in checkout.spec.ts, two in the
    shortcode spec. Each of the five is generated once per checkout page and
    none sits inside a classic-checkout guard, so all five run on both
    checkout types; the shortcode spec is classic by definition.

    This batch moves no coverage. Both specs stay in the browser and keep
    every title they have. Besides the selectors, the diff carries the order
    note's text and one blank line dropped in the shortcode spec; that spec
    is otherwise byte-identical to the migration branch's version.

    One deliberate departure from the migration branch. In the shared
    placeOrder() helper it swapped .check() for .click() on the order-note
    checkbox and deleted the comment recording why the step exists. check()
    asserts the element is a checkbox and that it ends up checked, throwing
    if it does not, and is a no-op when the box is already checked; click()
    asserts neither, and on an already-checked box it would uncheck it -
    after which the Blocks checkout stops rendering the textarea the next
    fill() targets, since it sits behind a withOrderNotes condition, so that
    call would fail with the element not found. No commit message explains
    the swap and it has nothing to do with moving a layer, so trunk's call
    and its comment are kept. That helper step runs on the blocks checkout
    only.

    Consolidates six mega-branch commits, subjects verbatim:
    - refactor(e2e): remove cross-profile checkout setup
    - test: Fix lower-layer migration CI regressions
    - fix(e2e): handle hidden classic checkout terms
    - fix(e2e): set terms state for custom checkout
    - fix(e2e): satisfy shortcode checkout prerequisites
    - test(checkout): Fix payment method selection

    Three of those cancel out between the diff base and the frozen state:
    the terms handling they add and remove is absent from both endpoints, so
    none of it reaches this diff. They are listed because they touch these
    paths, not because they contribute a line. The payment-method fix
    supplies the five exact selectors in checkout.spec.ts, and the shortcode
    prerequisites commit the two in the shortcode spec. The cross-profile
    cleanup supplies what remains: the order note's text, and a blank line
    dropped in the shortcode spec. It is also where the .check() swap came
    from, as part of collapsing an if/else that removed the terms branch.

    Refs TESTOPS-288
    Refs #68046

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

diff --git a/plugins/woocommerce/changelog/testops-288-checkout-shortcode-flows b/plugins/woocommerce/changelog/testops-288-checkout-shortcode-flows
new file mode 100644
index 00000000000..f32b80e1b06
--- /dev/null
+++ b/plugins/woocommerce/changelog/testops-288-checkout-shortcode-flows
@@ -0,0 +1,4 @@
+Significance: patch
+Type: dev
+Comment: Make checkout payment-method selectors exact in two retained E2E specs.
+
diff --git a/plugins/woocommerce/tests/e2e/tests/checkout/checkout-shortcode-custom-place-order-button.spec.ts b/plugins/woocommerce/tests/e2e/tests/checkout/checkout-shortcode-custom-place-order-button.spec.ts
index 27e8eb8b63a..48f2a000358 100644
--- a/plugins/woocommerce/tests/e2e/tests/checkout/checkout-shortcode-custom-place-order-button.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/checkout/checkout-shortcode-custom-place-order-button.spec.ts
@@ -158,7 +158,7 @@ test.describe( 'Shortcode Checkout Custom Place Order Button', () => {
 				.fill( customer.billing.email );

 			// Selecting Cash on Delivery first.
-			await page.getByText( 'Cash on delivery' ).click();
+			await page.getByText( 'Cash on delivery', { exact: true } ).click();

 			// Ensuring the default button is visible and the custom button is not.
 			await expect( page.locator( '#place_order' ) ).toBeVisible();
@@ -184,7 +184,7 @@ test.describe( 'Shortcode Checkout Custom Place Order Button', () => {
 			await expect( page.locator( '#place_order' ) ).toBeHidden();

 			// Switching back to Cash on Delivery.
-			await page.getByText( 'Cash on delivery' ).click();
+			await page.getByText( 'Cash on delivery', { exact: true } ).click();

 			await page.waitForFunction( () => {
 				const form = document.querySelector( 'form.checkout' );
@@ -239,7 +239,6 @@ test.describe( 'Shortcode Checkout Custom Place Order Button', () => {
 			await expect(
 				page.getByTestId( 'custom-place-order-button' )
 			).toBeVisible();
-
 			await page.getByTestId( 'custom-place-order-button' ).click();

 			// Ensuring the order was placed successfully.
diff --git a/plugins/woocommerce/tests/e2e/tests/checkout/checkout.spec.ts b/plugins/woocommerce/tests/e2e/tests/checkout/checkout.spec.ts
index c7ce4bc5330..d56de68df78 100644
--- a/plugins/woocommerce/tests/e2e/tests/checkout/checkout.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/checkout/checkout.spec.ts
@@ -91,7 +91,7 @@ async function placeOrder( page: Page ) {
 		// this helps with flakiness on clicking the Place order button
 		await page
 			.getByPlaceholder( 'Notes about your order' )
-			.fill( 'This order was created by an end-to-end test.' );
+			.fill( 'Test note' );
 	}

 	await page.getByRole( 'button', { name: 'Place order' } ).click();
@@ -279,7 +279,7 @@ checkoutPages.forEach( ( { name, slug } ) => {
 			);
 			const newCustomer = getFakeCustomer();
 			await fillBillingDetails( page, newCustomer.billing, false );
-			await page.getByText( 'Cash on delivery' ).click();
+			await page.getByText( 'Cash on delivery', { exact: true } ).click();
 			await placeOrder( page );
 			await page.goto( 'my-account/' );
 			await expect( page.locator( '#username' ) ).toBeVisible();
@@ -301,7 +301,9 @@ checkoutPages.forEach( ( { name, slug } ) => {
 			);
 			const newCustomer = getFakeCustomer();
 			await fillBillingDetails( page, newCustomer.billing, true );
-			await page.getByText( 'Direct bank transfer' ).click();
+			await page
+				.getByText( 'Direct bank transfer', { exact: true } )
+				.click();
 			await placeOrder( page );
 			await page.goto( 'my-account/' );
 			await expect(
@@ -328,7 +330,9 @@ checkoutPages.forEach( ( { name, slug } ) => {
 				tax
 			);

-			await page.getByText( 'Direct bank transfer' ).click();
+			await page
+				.getByText( 'Direct bank transfer', { exact: true } )
+				.click();
 			await placeOrder( page );
 		}
 	);
@@ -426,7 +430,7 @@ checkoutPages.forEach( ( { name, slug } ) => {
 				await fillShippingCheckoutBlocks( page, shippingAddress );
 			}

-			await page.getByText( 'Cash on delivery' ).click();
+			await page.getByText( 'Cash on delivery', { exact: true } ).click();
 			await placeOrder( page );
 		}
 	);
@@ -476,7 +480,9 @@ checkoutPages.forEach( ( { name, slug } ) => {
 				} );
 			}

-			await page.getByText( 'Direct bank transfer' ).click();
+			await page
+				.getByText( 'Direct bank transfer', { exact: true } )
+				.click();
 			await placeOrder( page );
 		}
 	);