Skip to content

feat(eslint): add stable Playwright action locator rule - #44

Merged
Eli Bosley (elibosley) merged 1 commit into
unraid:mainfrom
Ajit-Mehrotra:codex/playwright-stable-action-locators
Aug 6, 2026
Merged

feat(eslint): add stable Playwright action locator rule#44
Eli Bosley (elibosley) merged 1 commit into
unraid:mainfrom
Ajit-Mehrotra:codex/playwright-stable-action-locators

Conversation

@Ajit-Mehrotra

@Ajit-Mehrotra Ajit Mehrotra (Ajit-Mehrotra) commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add an opt-in limetech-playwright/prefer-stable-action-locator rule
  • flag static copy locators only when they drive Playwright actions, including role/name and hasText constraints
  • allow stable test IDs, dynamic scenario data, role-only actions, and copy/accessibility assertions
  • document the adoption pattern and the reason the rule is not enabled by default

Why

Action steps such as getByText("Save").click() become brittle when consumer applications translate or revise UI copy. A stable semantic test ID keeps the journey coupled to behavior instead of wording. The policy remains opt-in because third-party surfaces and accessibility-first suites cannot always add IDs and may intentionally use role/name action locators.

Validation

  • pnpm test — 41 tests passed
  • pnpm run format:check — passed
  • git diff --check — passed
  • diagnostic scan of Account E2E — 75 findings across 58 TypeScript files, confirming the rule targets the existing pattern

Consumer follow-up

After this ships in a release, Account can enable the rule for its E2E files and migrate action targets to stable test IDs incrementally. The diagnostic findings should be triaged rather than fixed blindly, especially for third-party, dynamic-data, and accessibility-specific interactions.

Summary by CodeRabbit

  • New Features

    • Added an opt-in Playwright lint rule that flags actions relying on static UI text, helping tests use more stable locators.
    • Supports common locator patterns, including role-based names, text filters, aliases, and wrapped expressions.
    • Allows dynamic locators, role-only locators, and text-based locators used for assertions.
  • Documentation

    • Documented rule configuration, supported Playwright files, recommended data-testid usage, and documented exceptions.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d936f3ba-4a35-4fdd-aec2-445526586314

📥 Commits

Reviewing files that changed from the base of the PR and between da3519e and 2d034ac.

📒 Files selected for processing (3)
  • README.md
  • src/eslint/playwright.js
  • test/playwright-stable-action-locators.test.mjs

📝 Walkthrough

Walkthrough

The PR adds an opt-in Playwright ESLint rule that reports static copy-based locators used for actions. It supports locator aliases and wrappers, includes tests for allowed patterns, and documents configuration and exceptions.

Changes

Stable action locators

Layer / File(s) Summary
Locator analysis and rule reporting
src/eslint/playwright.js
The rule resolves locator wrappers, lexical variables, aliases, and copy-based selectors. It reports static copy locators used as action receivers.
Playwright plugin wiring
src/eslint/playwright.js
The local Playwright plugin exposes the rule and registers it with the Playwright configuration.
Rule validation and documentation
test/playwright-stable-action-locators.test.mjs, README.md
Tests cover flagged and allowed locator patterns. The README documents configuration, behavior, and exceptions.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ESLint
  participant PlaywrightSpec
  participant PreferStableActionLocator
  participant LocatorAnalysisHelpers
  ESLint->>PlaywrightSpec: load Playwright configuration
  PlaywrightSpec->>PreferStableActionLocator: inspect locator action
  PreferStableActionLocator->>LocatorAnalysisHelpers: resolve locator chain
  LocatorAnalysisHelpers-->>PreferStableActionLocator: return selector classification
  PreferStableActionLocator-->>ESLint: report static copy locator
Loading

Possibly related PRs

Suggested reviewers: elibosley

Poem

A rabbit checks each locator line,
Static words must yield to a stable sign.
Aliases traced through every chain,
Assertions keep their copy plain.
Tests and docs now mark the way,
For sturdier actions every day.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@elibosley
Eli Bosley (elibosley) marked this pull request as ready for review August 6, 2026 14:44
@elibosley
Eli Bosley (elibosley) merged commit 8db29de into unraid:main Aug 6, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants