Skip to content

test(e2e): use exact name matching on getByRole across all specs - #61

Merged
iskhakovt merged 2 commits into
mainfrom
test/e2e-exact-role-names
Apr 19, 2026
Merged

iskhakovt merged 2 commits into
mainfrom
test/e2e-exact-role-names

Conversation

@iskhakovt

@iskhakovt iskhakovt commented Apr 19, 2026 •

Copy link
Copy Markdown
Owner

Summary

Sweep adds exact: true to all 155 getByRole({ name: "..." }) call sites in e2e/. Fixes the deterministic flake that has caused the last 3 main failures in group-cta.spec.ts.

Why

Playwright's getByRole name 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:

page.getByRole("button", { name: "Start" }).click();

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:

  • Fixture wrapper (monkey-patch page.getByRole to default exact: true) — feasible (all calls are on Page, no chained Locator.getByRole) but rejected because it silently diverges from Playwright's documented behavior; next reader has to hunt down the wrapper.
  • Playwright config default — doesn't exist. Maintainers declined to change ("We decided to keep our text matchers case-insensitive by default and do not intend to change it").
  • Per-call exact: true — what all the community guides recommend. Mechanical and self-documenting.

Scope

  • 155 string-name call sites updated (added , exact: true)
  • 7 regex-name call sites (e.g. name: /What do these ratings mean/) left alone — regex already expresses matching intent explicitly
  • 1 name: new RegExp(...) call site left alone (same reason)
  • Zero behavior changes expected in any existing test — inspection of unique button labels (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 matches

Test plan

  • pnpm -r typecheck
  • pnpm biome check e2e/
  • CI e2e passes (this is the test)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Enhanced end-to-end test precision by implementing stricter element matching across test suites, improving test reliability and reducing false positives from partial text matches.

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]>
@iskhakovt
iskhakovt enabled auto-merge (squash) April 19, 2026 17:45
@coderabbitai

coderabbitai Bot commented Apr 19, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 70cc8abd-66c2-497b-9f21-b173a8746b23

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This pull request systematically updates Playwright element selectors across 22 e2e test files to require exact accessible name matching by adding exact: true to all getByRole() calls, changing selector behavior from partial to strict equality matching while preserving all test control flows.

Changes

Cohort / File(s) Summary
Core Test Specs
e2e/answer-variety.spec.ts, e2e/completion.spec.ts, e2e/edit-post-completion.spec.ts, e2e/encryption-key.spec.ts, e2e/fill-questionnaire.spec.ts, e2e/filtered-mode.spec.ts, e2e/fresh-user-no-preseed.spec.ts, e2e/group-cta.spec.ts, e2e/multi-tab.spec.ts, e2e/realtime-status.spec.ts, e2e/reconnect-resume.spec.ts, e2e/refresh.spec.ts, e2e/results.spec.ts, e2e/self-pick-flow.spec.ts, e2e/sync-conflict.spec.ts, e2e/three-person.spec.ts, e2e/two-player.spec.ts
Added exact: true to getByRole() selectors for buttons (Start, I'm done, Continue, Progress, Review answers, etc.) and radio options (Yes, No, Maybe, Vulva, Penis, etc.) to enforce strict name matching instead of partial matches.
Visual Test Specs
e2e/visual/admin-flow.spec.ts, e2e/visual/partner-flow.spec.ts, e2e/visual/results-edge.spec.ts, e2e/visual/three-person.spec.ts
Added exact: true to Playwright role-based selectors for button clicks and radio selections to require exact accessible name matching in visual e2e test interactions.
Test Helpers
e2e/helpers.ts
Updated helper functions to use exact: true in getByRole() calls for Start button, rating radio options, View all categories button, and Now button, standardizing strict element matching across reusable test utilities.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Poem

🐰 Hop, hop, hooray! A selector quest so keen,
Where exact: true makes matches crisp and clean,
No partial whispers, just precision's call—
The playtest burrows celebrate it all! 🎯✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding exact name matching to all getByRole calls across all e2e test specifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/e2e-exact-role-names

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 627bd2c and 18a2540.

📒 Files selected for processing (22)
  • e2e/answer-variety.spec.ts
  • e2e/completion.spec.ts
  • e2e/edit-post-completion.spec.ts
  • e2e/encryption-key.spec.ts
  • e2e/fill-questionnaire.spec.ts
  • e2e/filtered-mode.spec.ts
  • e2e/fresh-user-no-preseed.spec.ts
  • e2e/group-cta.spec.ts
  • e2e/helpers.ts
  • e2e/multi-tab.spec.ts
  • e2e/realtime-status.spec.ts
  • e2e/reconnect-resume.spec.ts
  • e2e/refresh.spec.ts
  • e2e/results.spec.ts
  • e2e/self-pick-flow.spec.ts
  • e2e/sync-conflict.spec.ts
  • e2e/three-person.spec.ts
  • e2e/two-player.spec.ts
  • e2e/visual/admin-flow.spec.ts
  • e2e/visual/partner-flow.spec.ts
  • e2e/visual/results-edge.spec.ts
  • e2e/visual/three-person.spec.ts

Comment thread e2e/helpers.ts Resolved
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]>
@iskhakovt
iskhakovt enabled auto-merge (squash) April 19, 2026 19:18
@iskhakovt
iskhakovt merged commit 26ccdb3 into main Apr 19, 2026
8 checks passed
@iskhakovt
iskhakovt deleted the test/e2e-exact-role-names branch April 19, 2026 19:21
@coderabbitai coderabbitai Bot mentioned this pull request Apr 19, 2026
3 of 4 tasks
iskhakovt added a commit that referenced this pull request Apr 19, 2026
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]>
iskhakovt added a commit that referenced this pull request Apr 19, 2026
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]>
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.12.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant