Skip to content

feat(locator): add a context-wide visibility default - #43859

Merged
Pavel Feldman (pavelfeldman) merged 2 commits into
mainfrom
triage/43855/41497817641-1
Nov 2, 2026
Merged

Pavel Feldman (pavelfeldman) merged 2 commits into
mainfrom
triage/43855/41497817641-1

Conversation

@microsoft-playwright-automation

Copy link
Copy Markdown
Contributor

Add the opt-in locatorIncludeHidden: false context/test option and per-locator includeHidden overrides. Keep the unfiltered selector separate so automatic visibility filtering applies only when resolving the final locator.

Overrides survive same-element transformations; descendant locators use the context default again. Existing role accessibility rules and the default matching behavior remain unchanged.

A separate context test is needed because the existing strict-selector and page visibility tests do not configure this context default. Existing visibility and configuration tests are extended.

Verified on Linux: 275 context/locator tests, 64 parser/generator tests and 6 configuration tests passed; one test was skipped. Both regression tests fail without automatic filtering in all three browsers. Build and flint passed.

Fixes #43855

Triaged on Linux by the Playwright bot - agent run

@github-actions

This comment has been minimized.

@pavelfeldman

Copy link
Copy Markdown
Member

Make it omitHidden instead of includeHidden with false being the default across the board.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Hi, I'm the Playwright bot. I started to address the review comments on Linux: agent run

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

🟢 Both failures are pre-existing flakes

Hi, I'm the Playwright bot. I checked the failed jobs, the PR changes, and refreshed CI history. Neither failure looks caused by this PR.

Details

The two failures in the latest merged report, for PR commit 857e3a4, both occur on unrelated commits. The new locator visibility filter is opt-in, and neither test enables it. The PR does not change worker teardown or trace screencast capture.

Pre-existing flake / infra

  • Windows: [playwright-test] › playwright.spec.ts:1131 › should pause test timeout while on pause — the inner test passes, but worker teardown exceeds 3000 ms, producing exit code 1. The same test has the identical teardown timeout on the same Windows bot in fix(test runner): rename built-in lock to -exclusive- #43858, commit afb1ed4 (job log). Refreshed history excluding this PR shows 502 passing and 2 failing run attempts on that bot.

  • Chromium / Ubuntu: [chromium-library] › library/video.spec.ts:762 › screencast › VI-030 should work with video+trace — all four attempts fail because the trace contains no screencast-frame, so reading frame.file throws. The same test and error occur on main at 9a6aac0: it fails three attempts, then passes on the fourth (run). This confirms the failure can occur without this PR.

CI failures checked by the Playwright bot - agent run

Triaged by the Playwright bot - agent run

@microsoft-playwright-automation

Copy link
Copy Markdown
Contributor Author

Hi, I'm the Playwright bot and I revised the option names and defaults.

Pavel Feldman (@pavelfeldman): Changed the context/test option to locatorOmitHidden and per-locator options to omitHidden, with false as the default. Updated documentation, generated types and tests. The existing role-selector includeHidden option is unchanged.

Verified on Linux: 171 context/locator tests across Chromium, Firefox and WebKit, 64 parser/generator tests, and four configuration tests passed. Both regression tests failed without the implementation in all three browsers. Build and flint passed. Headed mode, other operating systems and language ports were not tested.

Revised on Linux by the Playwright bot - agent run

@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Test results for "MCP"

5194 passed, 616 skipped


Merge workflow run.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Test results for "tests 1"

23588 passed, 705 skipped


Merge workflow run.

@pavelfeldman
Pavel Feldman (pavelfeldman) marked this pull request as ready for review November 2, 2026 20:48

if (options?.visible !== undefined)
this._selector += ` >> visible=${options.visible ? 'true' : 'false'}`;
this._selectorWithoutVisibility += ` >> visible=${options.visible ? 'true' : 'false'}`;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We are adding visibility here whereas the field is _selectorWithoutVisibility

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It is correct here. When visible is requested on this level, it should be baked into the locator's selectorWithoutVisibility. Only the last token's visible is dynamic.

(this as any)[inspect.custom] = () => this._inspect();
}

get _selector(): string {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we make it a method for clarity?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The world will break.

@pavelfeldman
Pavel Feldman (pavelfeldman) merged commit 7542bfb into main Nov 2, 2026
32 checks passed
@pavelfeldman
Pavel Feldman (pavelfeldman) deleted the triage/43855/41497817641-1 branch November 2, 2026 21:30
@miso-belica

Copy link
Copy Markdown

Wow, that's it? Is it really done? In a few hours from the issue created? Thanks 👏

Do you have a regular release or it is more an irregular batch of features? Can we really expect this in the next version?

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.

[Feature]: Option to make all locators ignore hidden elements by default

3 participants