Repository navigation
test(e2e): use exact name matching on getByRole across all specs - #61
Conversation
Playwright's getByRole defaults to substring matching on `name`, which caused group-cta.spec.ts to flake after PR #58 introduced a second "Review from the start" button: `{ name: "Start" }` matched both that button and the intended "Start" CTA, and the wrong element would detach mid-click → TimeoutError (3/3 recent main failures, all the same test + line). Sweep adds `exact: true` to all 155 call sites that use a string name. Regex names (7) are left alone — they already express intent explicitly. Playwright maintainers (microsoft/playwright#27483) have declined to change the default, and the documented community practice is per-call opt-in rather than a fixture wrapper, so the sweep is mechanical. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThis pull request systematically updates Playwright element selectors across 22 e2e test files to require exact accessible name matching by adding Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@e2e/helpers.ts`:
- Line 251: The locator for the fantasy radio is using exact: true with the
wrong label; update the locator used in e2e/helpers.ts (the call
page.getByRole("radio", { name: "Fantasy", exact: true }).click()) to match the
actual exact label (e.g., change name to "Fantasy only") or remove exact: true
so the existing "Fantasy" match works; ensure only the matching label is used so
the radio is reliably selected during tests.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: ac809c6d-1f0e-487f-a235-2ba98b5606c1
📒 Files selected for processing (22)
e2e/answer-variety.spec.tse2e/completion.spec.tse2e/edit-post-completion.spec.tse2e/encryption-key.spec.tse2e/fill-questionnaire.spec.tse2e/filtered-mode.spec.tse2e/fresh-user-no-preseed.spec.tse2e/group-cta.spec.tse2e/helpers.tse2e/multi-tab.spec.tse2e/realtime-status.spec.tse2e/reconnect-resume.spec.tse2e/refresh.spec.tse2e/results.spec.tse2e/self-pick-flow.spec.tse2e/sync-conflict.spec.tse2e/three-person.spec.tse2e/two-player.spec.tse2e/visual/admin-flow.spec.tse2e/visual/partner-flow.spec.tse2e/visual/results-edge.spec.tse2e/visual/three-person.spec.ts
The sweep to exact matching exposed that answerQuestionsCycling was targeting a radio named "Fantasy", but the actual UI label is "Fantasy only" (strings.ts:52). Substring matching had been hiding this all along. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
getByText substring-matches case-insensitively, so any two DOM nodes
whose text overlaps can fight over a selector (e.g. a button's "Each
person" label and a helper paragraph that mentions "each person" will
both match getByText("Each person")). Follows the direction of #61,
which tightened getByRole calls — this does the same for the getByText
clicks that slipped through.
- Buttons: getByText("X").click() -> getByRole("button", { name: "X", exact: true }).click()
- Radios (ToggleGroup): getByText("X").click() -> getByRole("radio", { name: "X", exact: true }).click()
- Category rows ("Essentials", "Adventurous") render compound button
text ("Essentials 0/15"), so keep getByText but add exact: true —
matches the pure-label <span> and bubbles to the parent button.
- QuestionCard's back button uses aria-label="Previous question" —
three call sites updated to match the accessible name.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
getByText substring-matches case-insensitively, so any two DOM nodes
whose text overlaps can fight over a selector (e.g. a button's "Each
person" label and a helper paragraph that mentions "each person" will
both match getByText("Each person")). Follows the direction of #61,
which tightened getByRole calls — this does the same for the getByText
clicks that slipped through.
- Buttons: getByText("X").click() -> getByRole("button", { name: "X", exact: true }).click()
- Radios (ToggleGroup): getByText("X").click() -> getByRole("radio", { name: "X", exact: true }).click()
- Category rows ("Essentials", "Adventurous") render compound button
text ("Essentials 0/15"), so keep getByText but add exact: true —
matches the pure-label <span> and bubbles to the parent button.
- QuestionCard's back button uses aria-label="Previous question" —
three call sites updated to match the accessible name.
Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
|
🎉 This PR is included in version 1.12.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Summary
Sweep adds
exact: trueto all 155getByRole({ name: "..." })call sites ine2e/. Fixes the deterministic flake that has caused the last 3 main failures ingroup-cta.spec.ts.Why
Playwright's
getByRolename matching defaults to substring. That was fine until PR #58 landed a second button whose accessible name contains "Start" ("Review from the start"). After that:resolved to whichever of the two happened to be on screen at the moment — and in the loop on
group-cta.spec.ts:55, the wrong one detached mid-click, timing out.3 of the last 3 main runs failed on this exact test + line:
Approach
Researched alternatives before picking the mechanical sweep:
page.getByRoleto defaultexact: true) — feasible (all calls are onPage, no chainedLocator.getByRole) but rejected because it silently diverges from Playwright's documented behavior; next reader has to hunt down the wrapper.exact: true— what all the community guides recommend. Mechanical and self-documenting.Scope
, exact: true)name: /What do these ratings mean/) left alone — regex already expresses matching intent explicitlyname: new RegExp(...)call site left alone (same reason)Start,Continue,I'm done,Now,Later,Progress,View my answers,Review answers,Edit my answers,Skip question,Start filling out,View all categories,View group members) confirms none were intentionally relying on substring matchesTest plan
pnpm -r typecheckpnpm biome check e2e/🤖 Generated with Claude Code
Summary by CodeRabbit