feat(Playwright): visibleLocator config option - #5707
Open
DavertMik wants to merge 1 commit into
Open
Conversation
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
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 used to find elements match only visible ones, so actions no longer pick a hidden duplicate and then time out on actionability.
How it resolves
One value is read at the
findElementschokepoint:Step opts beat helper config, the same way
exact,strictModeandelementIndexalready work.visibleLocatoris documented in theStepOptionstypedef alongside them..visible()is applied everywhere a Locator becomes an element array — the plainmatcher.locator(),handleRoleLocator,findByPlaywrightLocator({pw:}locators), the twogetByRole('button'|'link')fallbacks infindClickable, andfindByRole(selectOption's combobox/listbox path).findClickable,findCheckableandfindFieldsall bottom out there, so click, check, fill, select, attach, focus and moveCursorTo are covered without threading a parameter through them.withVisibleLocatorthrows a named error if the installed Playwright predates 1.63, sinceplaywrightis a peer install.Behaviour changes when enabled
strict: trueignores hidden duplicates, so cases that previously failed withMultipleElementsFoundnow pass.input— are no longer found.Not covered
seeElementInDOM,dontSeeElementInDOMandseeNumberOfElementsopt out by writingvisibleLocator: falseinto the current step's opts, since they assert DOM presence regardless of visibility. That opt-out only fires inside a recorded step — called directly on a helper instance outside a step, they filter. This is the same blind spot every existing step opt has.dragAndDroppasses selectors to Playwright directly rather than building a Locator, so it is excluded and named as such in the config docs.Testing
playwrightdevDependency bumped to^1.63.0.8 tests in
test/helper/webapi.js, following the existing#elementIndex step optionpattern and reusing the/invisible_elementsfixture: config on/off, per-step on/off, all-hidden → not found, DOM assertions unaffected, fields/checkboxes, plus a combobox case covering thefindByRolepath. Guarded withisHelper('Playwright'), so Puppeteer and WebDriver skip them.seeTrafficand twomakeApiRequesttests, all hitting external hosts and failing identically on a clean tree.test/acceptance/codecept.Playwright.js): 59 passed, 1 failed — thelocalhost:3001API call, also failing on a clean tree.Note for review
PlaywrightLocator.jsnow importswithVisibleLocatorfromPlaywright.js, which already imports it back. The cycle resolves (function declarations hoist, the call happens at runtime) andPlaywright.jsis the only importer of that module. If a cycle is unwelcome on this branch, moving the two resolver functions intolib/helper/extras/breaks it.🤖 Generated with Claude Code
https://claude.ai/code/session_01D6RydiYkagn6C8Pts2Leou