feat(Playwright): visibleLocator config option - #5707
Merged
Conversation
DavertMik
force-pushed
the
feature/playwright-visible-locator
branch
2 times, most recently
from
September 9, 2026 23:27
36ac791 to
5793d13
Compare
Appends Playwright's locator.visible() (1.63+) to locators, so actions
match only visible elements. Resolved per step: stepOpts({ visibleLocator })
overrides the helper config, following exact/strictMode/elementIndex.
seeElementInDOM, dontSeeElementInDOM and seeNumberOfElements opt out by
setting the step option, since they assert DOM presence regardless of
visibility.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D6RydiYkagn6C8Pts2Leou
DavertMik
force-pushed
the
feature/playwright-visible-locator
branch
from
September 9, 2026 23:34
5793d13 to
28398d4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a
visibleLocatoroption to the Playwright helper, built onlocator.visible()from Playwright 1.63.When enabled, locators match only visible elements, so actions no longer pick a hidden duplicate and then time out on actionability.
How it resolves
_beforeStepdecides once per step and writes the answer to the store:Step opts beat helper config, the same way
exact,strictModeandelementIndexalready work.visibleLocatoris documented in theStepOptionstypedef alongside them.Because the answer is already in the store,
withVisibleLocatoris a plain function — nothing is threaded through signatures and nothing needs binding:It wraps the five places a Locator is built:
findElements(plain and{pw:}branches),handleRoleLocator,findByRole, and the twogetByRole('button'|'link')fallbacks infindClickable.findClickable,findCheckableandfindFieldsall bottom out there, so click, check, fill, select, attach, focus and moveCursorTo are covered. Every existing call site is untouched.findByPlaywrightLocatornow returns a Locator instead of an array, with.all()applied byfindElements. That keeps the{pw:}path uniform with the others and fixes itsgetByTestIdbranch, which previously returned a bare Locator to callers expecting an array.A named error is thrown if the installed Playwright predates 1.63, since
playwrightis a peer install.Note: this makes Playwright the first helper in
lib/helper/to define_beforeStep, which adds one recorder task per step. It is a synchronous store write, negligible against a browser round-trip, but worth stating.Behaviour changes when enabled
strict: trueignores hidden duplicates, so cases that previously failed withMultipleElementsFoundnow pass.input— are no longer found.Not covered
seeElementInDOM,dontSeeElementInDOMandseeNumberOfElementsare excluded in_beforeStep, since they assert DOM presence regardless of visibility.dragAndDroppasses selectors to Playwright directly rather than building a Locator, so it is excluded and named as such in the config docs.grabTextFrom's CSS path callspage.textContent(selector)and never goes through_locate, so it does not filter. Its role-locator path does. That divergence predates this PR.Testing
playwrightdevDependency bumped to^1.63.0.9 tests in
test/helper/Playwright_test.js. They live in the Playwright helper spec rather than the sharedwebapi.jsone, since the option exists only in this helper. They drive_beforeStepdirectly, so the exclusion and override logic is exercised rather than bypassed: config on/off, per-step on/off, all-hidden → not found, DOM assertions unaffected,{pw:}locators, a combobox case coveringfindByRole, and fields/checkboxes.webapi.jsis unchanged.Verified locally: unit suite 815 passed / 0 failed, and the 9 new tests pass. The browser helper and acceptance suites are left to CI.
Note on CI: the Obscura Helper Tests job fails on
#waitInUrland the#checkOption - ARIA rolescases. Those fail identically on base4.xat cfc9545 and are unrelated to this PR.🤖 Generated with Claude Code
https://claude.ai/code/session_01D6RydiYkagn6C8Pts2Leou