From 79b7c802647b9fe8960eb57890139a72fb262ee7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrew=20Beveridge=20=E2=98=84=EF=B8=8F?= Date: Wed, 26 Aug 2026 12:38:31 -0400 Subject: [PATCH] fix(e2e): fill Stripe Checkout name + ZIP fields (daily E2E false alarm) (#945) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Problem The daily **E2E Daily Test โ€” Stage 1: Credit Purchase** (run #146) fired the Discord alert *"๐Ÿšจ Payment flow is broken. Customers may not be receiving credits."* on all 3 retries. This was **test drift, not a production outage.** Stripe's hosted Checkout now renders **required** *Name on card* and *ZIP code* fields, but the test helper's fill locators no longer matched their current accessible names, so both were left blank. Stripe blocked the "Pay" click (`Please provide the name on your card` / `Your ZIP code is invalid`), the page never redirected, and the 60s `waitForURL` timed out. Root cause confirmed from the failed run's `error-context.md` + `test-failed-1.png` (both validation errors visible on the stuck Checkout page). Prod `/api/health` was healthy throughout, and real customers fill these fields themselves โ€” so checkout is unaffected. ## Fix (`frontend/e2e/helpers/stripe-checkout.ts`, test-only) - **Name** locator now matches `/name on card|cardholder name/i`, placeholder `First and last name`, and `[data-elements-stable-field-name="billingName"]`. - **ZIP** locator drops the broken `^zip$` anchor (the accessible name is "ZIP code") โ†’ `/zip|postal code/i`. - Bumped the too-short 2s field-search timeouts to 8s; added WARNING logs when a field isn't found. - Defaulted the cardholder name so a missing/empty secret can't silently reblank it. ## Verification Ran `credit-purchase-real.spec.ts` against **production with a real $3 charge**: checkout completed, redirected to **"Payment Successful ยท 2 credits available"**, and the *"1 credits added"* confirmation email arrived. Old locator regexes tested `false` against the real snapshot strings; new ones test `true`. Typecheck clean. CodeRabbit local review: no findings. > Note: a ~600s "Test timeout exceeded" seen locally *after* the body passes is an environmental macOS teardown quirk (production config uses `trace:'on'`+`video:'on'`), reproducible with a bare navigate-and-close test โ€” it does not occur on CI's Ubuntu runners. @coderabbitai ignore ๐Ÿค– Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.8 (1M context) --- frontend/e2e/helpers/stripe-checkout.ts | 37 +++++++++++++++++++------ 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/frontend/e2e/helpers/stripe-checkout.ts b/frontend/e2e/helpers/stripe-checkout.ts index 0e0bf338..5ba3c795 100644 --- a/frontend/e2e/helpers/stripe-checkout.ts +++ b/frontend/e2e/helpers/stripe-checkout.ts @@ -48,7 +48,9 @@ function getCardDetailsFromEnv(): CardDetails { ); } - return { number, expiry, cvc, name }; + // Default the name so a missing/empty secret can't leave the (now required) + // "Name on card" field blank and get the Pay click rejected. + return { number, expiry, cvc, name: name || 'E2E Test' }; } /** @@ -155,34 +157,51 @@ export async function completeStripeCheckout(page: Page): Promise { console.log(' Filling CVC...'); await fillCardField(page, 'cardCvc', card.cvc); - // Step 6: Fill cardholder name if the field exists (any frame) + // Step 6: Fill cardholder name if the field exists (any frame). + // Stripe renames/relabels this field across layouts โ€” we've seen the + // accessible name be "Cardholder name", "Name on card", or "Full name on + // card", and the placeholder be "Full name on card" or "First and last + // name". Match all known variants so an empty name field can't silently + // block the Pay button (which produced a false "payment broken" alarm โ€” the + // Pay click was rejected with "Please provide the name on your card"). if (card.name) { const nameInput = await locateVisibleInFrames( page, (f) => f - .locator('#billingName, input[name="billingName"], input[placeholder="Full name on card"]') - .or(f.getByRole('textbox', { name: /cardholder name/i })), - 2_000 + .locator( + '[data-elements-stable-field-name="billingName"], #billingName, input[name="billingName"], input[placeholder="Full name on card"], input[placeholder="First and last name"]' + ) + .or(f.getByRole('textbox', { name: /name on card|cardholder name/i })), + 8_000 ); if (nameInput) { console.log(' Filling cardholder name...'); await nameInput.fill(card.name); + } else { + console.log(' WARNING: cardholder name field not found โ€” Pay may be rejected'); } } - // Step 6b: Fill ZIP code (required for US cards) โ€” search any frame + // Step 6b: Fill ZIP code (required for US cards) โ€” search any frame. + // The accessible name is "ZIP code" (not exactly "ZIP"), so the regex must + // not anchor to ^zip$. Placeholder is often absent, so rely on the stable + // field name / accessible name too. const zipInput = await locateVisibleInFrames( page, (f) => f - .locator('#billingPostalCode, input[name="billingPostalCode"], input[placeholder="ZIP"]') - .or(f.getByRole('textbox', { name: /^zip$|postal code/i })), - 2_000 + .locator( + '[data-elements-stable-field-name="billingPostalCode"], #billingPostalCode, input[name="billingPostalCode"], input[placeholder="ZIP"]' + ) + .or(f.getByRole('textbox', { name: /zip|postal code/i })), + 8_000 ); if (zipInput) { console.log(' Filling ZIP code...'); await zipInput.fill(process.env.E2E_STRIPE_ZIP || '10001'); + } else { + console.log(' WARNING: ZIP code field not found โ€” Pay may be rejected'); } // Step 6c: Uncheck "Save my information" to avoid a phone-number requirement