Repository navigation
feat(web): run a selector inside a locator with browser.locator(css, { within }) (ENG-1211) - #2334
KrzysztofMoch wants to merge 3 commits into
Conversation
🟢 e2e web: 130 passedAll 130 tests in 48 files
Tested by e2e 0.26.0 · 1m 13s · web · run artifacts |
🟢 e2e web agent: 34 passed, 5 skipped35 agent steps · 26 replayed from cache · 25 model calls · 133.5k tokens (94% cached) · $0.0054 All 39 tests in 5 files
Tested by e2e 0.26.0 · 1m 29s · web · run artifacts |
🟢 e2e android agent: 20 passed24 agent steps · 15 replayed from cache · 43 model calls · 300.5k tokens (85% cached) · $0.0188 All 20 tests in 1 file
Tested by e2e 0.26.0 · 5m 35s · android-emulator · run artifacts |
MicrobenchmarksFor ⚪ No case changed by 0.5% or more. Repeatability: two builds of the head agree in every case, 10 trials each. Base A direction is reported only when the trial ranges of base and head do not overlap and the change is at least 0.5%. 4 unchanged cases
How this is measuredInstructions per iteration: the difference between a run of N and of 3N iterations, divided by 2N, so startup, loading, warmup, and compilation cancel. 5 trial(s) per case and checkout. Lower is better. Machine: linux x64, AMD EPYC, Node v26.13.1, valgrind-3.22.0, ASLR off.
Workflow run: each job's summary, and |
🟢 e2e ios: 67 passed, 1 skippedAll 68 tests in 8 files
Tested by e2e 0.26.0 · 8m 1s · ios-simulator · run artifacts |
🟢 e2e android: 68 passed, 1 skippedAll 69 tests in 8 files
Tested by e2e 0.26.0 · 10m 21s · android-emulator · run artifacts |
🔴 e2e ios agent: 5 failed, 16 passed, 1 skipped24 agent steps · 12 replayed from cache · 31 model calls · 174.0k tokens (87% cached) · $0.0098 🔴 act completes Flattened Registration Form MODEL_PROVIDER_FAILED
Evidence: screenshot, log 🔴 act completes Flattened Login MODEL_PROVIDER_FAILED
Evidence: screenshot, log 🔴 act completes Photo Picker MODEL_PROVIDER_FAILED
Evidence: screenshot, log 🔴 act completes Choice Controls MODEL_PROVIDER_FAILED
Evidence: screenshot, log 🔴 act completes Stripe PaymentSheet MODEL_PROVIDER_FAILED
Evidence: screenshot, log All 22 tests in 1 file
Tested by e2e 0.26.0 · 7m 50s · ios-simulator · run artifacts |
okwasniewski
left a comment
There was a problem hiding this comment.
Automated review (AI triage pass), not yet read by a maintainer.
Reviewed a702e40ec. Clean, well-tested addition: { kind: 'selector', scope } is projected as Playwright's own scope.locator(selector), every expression walker (web projection, frameSelectors, core resolveExpression, mobile, desktop guard, describeExpression) handles the new field, and the docs, skill, changesets, type test, and peer floor all match the code. No must-fix.
Verified locally (fresh worktree, full build):
scoped-selectors.test.ts11/11,frame-screen.test.ts, e2eexpression/resolve-expression/fixture-runtime(96), mobilelocate(21), desktopsurface(175), webtsc --noEmit(coverstests/types/locator-within.ts),mcp-run-code"mixes the code's screen..." all pass.- Mutation checks, each fails the new test: dropping the
composable.filter(filter)label fix (expected [ 'billing-v' ] to deeply equal []), restoringcase 'selector': return []inframeSelectors(frame case), restoring theinternals.context !== contextownership check (run_codecase fails withINVALID_LOCATOR). - Only the Playwright driver exists on main (#1503 not merged), and the projection is plain Playwright chaining, so Chromium, Firefox, and WebKit behave alike. The PR body already names what #1503 must carry over.
Should fix
- packages/web/src/browser.ts:1426 -
frame.locator(selector)still drops a second argument without a word. In JavaScript,browser.frameLocator('#grid').locator('td', { within: row })searches the whole frame. That is the same silent-ignore this PR fixes forbrowser.locator, and now the API invites the call. Takeoptions?: unknownand refuse anything other thanundefinedwithINVALID_LOCATOR, naming the fix (browser.locator(sel, { within }), where the within locator carries its frame). The PR body turned down a runtime arity check because "no fixture method checks arity", butrejectUnknownOptionsexists because of the policy in options.ts:1-6.
Nits
- packages/core/src/locator/screen.ts:379 - ownership now compares sessions, so a locator kept from an earlier test in a serial group or another test on a shared session (
serial.ts:417,suite-attempt.ts:214) is accepted. That is harmless because only the expression is reused, but the message, theexpressionOfJSDoc (engine/index.ts:278), and the engine.mdx:2436 row still say "another attempt" is refused. Say "another engine session" instead.
For the maintainer
- API shape: Playwright chains
row.locator(css), and itslocator(sel, options)bag takeshas/hasNot/hasText/hasNotText, notwithin. This PR puts a new key,within, into that same options position onbrowser.locator. So a Playwright port getsINVALID_LOCATOR ... it takes withinforhasText, and must turnrow.locator('td')inside out. The PR says ENG-1211 chose web-only with nolocator()on the sharedLocator(the type test pins this). Please confirm{ within }over a web-only chaining method (for examplebrowser.within(row).locator(css)) before this becomes public API. - The
@e2e-dev/webpeer floor rises to>=0.25.1for@e2e-dev/coreande2e. That fits only if the next core release is 0.25.1, and the two must ship together.
kdy1
left a comment
There was a problem hiding this comment.
Note
This text was drafted with AI and posted after human approval.
- Harness: T3 Code
- AI agents: coordinator: Claude Opus 5.5 (claude-opus-5-5), reviewer: GPT-6.2 Astra (gpt-6.2-astra), reviewer: GPT-6.2 Sol (gpt-6.2-sol), reviewer: Claude Opus 5.5 (claude-opus-5-5), reviewer: Claude Sonnet 5.5 (claude-sonnet-5-5)
Verdict: Approve
This review approves the pull request. The P3 items are optional and do not block the merge.
Reviewed commit: a702e40ec32bc2da32d60d2c05e0e3fc3ce63c1e
- P3 (non-blocking): 3 (3 inline)
a702e40 to
88c62e0
Compare
|
[claude-opus-5-5] responding on behalf of KrzysztofMoch One decision is left for a human: whether |
88c62e0 to
bf4ee4f
Compare
okwasniewski
left a comment
There was a problem hiding this comment.
Automated review (AI triage pass), not yet read by a maintainer.
Reviewed bf4ee4f71. The rebased head plus the docs/test follow-up fix all three of kdy1's P3s; the PR now conflicts with main in one file, and main's new expressionSelectors needs to learn about scope as part of that rebase.
Earlier findings against this head:
- kdy1, document order: fixed. web.mdx and the
contract.tsnote now say Playwright's chain order, andscoped-selectors.test.tspins the nestedarticlecase. - kdy1,
run_codetest can't fail: fixed. It counts*underitemsnow. - kdy1,
map(browser.locator)break: the check stays (owner decision), and the changeset now names themap((selector) => browser.locator(selector))form. - Ours,
frame.locatorsilently drops a 2nd arg: not addressed and got no reply (see Should fix). - Ours, "another attempt" wording: unchanged (nit below).
- Peer floor: moot. Main already has
>=0.25.1(#2255), and the rebase removed the PR's own bump.
Must fix
- Rebase on main.
docs/reference/engine.mdx(~L1909,resolveExpressionnotes) conflicts with #2237, which addedexpressionSelectorsfor engines whose selector language is async (electron). Keep both bullets. While you're there, resolve.ts:78 on main returns atcase 'selector'without walkingnode.scope, andnode satisfies neverchecks kinds, not fields, so tsc won't flag it. After the merge,expressionSelectors({ kind: 'selector', selector: 'td.price', scope: { kind: 'selector', selector: 'tr.grace' } })returns["td.price"](checked on a local merge). An engine that follows the documented pattern, like electron locate.ts:112, never queriestr.grace, so the scope resolves to nothing and the locator silently matches zero nodes. Fix:case 'selector': found.add(...); if (node.scope !== undefined) walk(node.scope);, plus a case in theexpressionSelectorsblock ofresolve-expression.test.ts.
Should fix
- browser.ts:1426 - this is still open from the last pass. In JS,
browser.frameLocator('#grid').locator('td', { within: row })dropswithinwithout a word and searches the whole frame. That's the same silent ignore thebrowser.locatorcheck exists to stop. Refuse a defined 2nd arg withINVALID_LOCATORand point tobrowser.locator(sel, { within }).
Nits
- screen.ts:398, engine/index.ts:278, engine.mdx:2453 still say "another attempt". The check compares engine sessions, so say "another engine session".
For the maintainer
- API shape:
{ within }inbrowser.locator's options slot vs a web-only chaining form (Playwright ports writerow.locator(css)). This was raised last pass and is still unconfirmed.
CI is green, but on the 2026-11-26 run. It will rerun after the rebase.
kdy1
left a comment
There was a problem hiding this comment.
Note
This text was drafted with AI and posted after human approval.
- Harness: T3 Code
- AI agents: coordinator: Claude Opus 5.5 (claude-opus-5-5), reviewer: GPT-6.2 Astra (gpt-6.2-astra), reviewer: GPT-6.2 Sol (gpt-6.2-sol), reviewer: Claude Opus 5.5 (claude-opus-5-5), reviewer: Claude Sonnet 5.5 (claude-sonnet-5-5)
Verdict: Request changes
This review requests changes. Fix the P2 items before merge. The P3 items are optional and do not block the merge.
The PR conflicts with main (base is 147 commits behind). git merge-tree reports conflicts in docs/browser.mdx (deleted on main), docs/reference/engine.mdx, docs/reference/web.mdx, and packages/core/src/engine/resolve.ts. The P2 below must be fixed as part of that rebase.
Reviewed commit: bf4ee4f71467222e53bbb800be67c83d5cbeb577
- P2 (fix before merge): 1 (1 inline)
- P3 (non-blocking): 3 (1 inline)
Items that cannot be inline
-
P3 · Non-blocking ·
frame.locatorstill ignores a second argument —packages/web/src/browser.ts:1426In JavaScript,
browser.frameLocator('#grid').locator('td', { within: row })dropswithinwithout an error and searches the whole frame. This is the same silent ignore that the newrejectUnknownOptionscall inbrowser.locator(packages/web/src/browser.ts:868) prevents, and the newwithinoption makes the call more likely. TypeScript rejects the call; JavaScript andrun_codecallers do not get that check. This was raised in an earlier review on this PR and has no reply. -
P3 · Non-blocking · "How it works" step 6 describes a peer-range change that is not in the diff — the whole change
Step 6 of the PR description says that the
@e2e-dev/webpeer floors on@e2e-dev/coreande2erise to0.25.1. The diff changes nopackage.json: both the base and the head already declare>=0.25.1(#2255).AGENTS.mdsays that a body and a diff that disagree are a review finding.
…locator (ENG-1211)
…ver nth= and closed shadow roots
A frame's locator() dropped a second argument without a word, so
frameLocator(...).locator('td', { within: row }) searched the whole frame.
It now throws INVALID_LOCATOR and points to browser.locator(selector,
{ within }). The ownership error names another engine session, which is
what it compares.
bf4ee4f to
1a84376
Compare
|
No actionable comments were generated in the recent review. Walkthrough
Change: Feature Merge Risk:
|
|
[claude-opus-5-5] responding on behalf of KrzysztofMoch Rebased onto main (
|
Docs previewBuilt from 1a84376: https://e2e-inc-docs-pr-2334.vercel.app/docs Changed pages: |
okwasniewski
left a comment
There was a problem hiding this comment.
Automated review (AI triage pass), not yet read by a maintainer.
Reviewed 1a8437618. Every finding from the last pass and from kdy1's dismissed review is fixed in the rebased head. I found nothing new to fix.
Earlier findings:
- Ours/kdy1 P2,
expressionSelectorsignoredscopeafter the rebase: fixed at resolve.ts:93. I removed that line and rebuilt core. The newresolve-expression.test.tscase then fails withexpected [ 'td.price' ] to deeply equal [ 'tr', '.grace', 'td.price' ]. frame.locatorsilently dropped a second argument: fixed. It now throwsINVALID_LOCATORand points tobrowser.locator(selector, { within })(browser.ts:1427). This has a test inframe-screen.test.ts, and the changeset andweb.mdxboth say a frame'slocatortakes no options.- Wording "another attempt": fixed.
screen.ts,engine/index.ts,engine.mdx, and the test constant now say "another engine session". - kdy1 P3
nth=on combined matches: documented inweb.mdxandcontract.ts. A Playwright cross-check case was added toscoped-selectors.test.ts. - kdy1 P3 peer floor claim in the body: fixed. Step 6 now says no peer floor moves.
- The earlier rebase conflict is gone. The PR merges cleanly into main
31a814ad9.
Verified locally on a fresh worktree with a full build: frame-screen and scoped-selectors 18/18, resolve-expression and scroll-until-visible 40/40. The line refs in the PR body match the code. All review threads are resolved.
CI: everything passes except ios agentic, android agentic, and mobile gate. Those fail on AI Gateway requires a positive credit balance, which is an infra problem, and this PR touches no mobile or agent code.
For the maintainer
- API shape is still unconfirmed (raised on 11-26 and 11-27):
{ within }sits inbrowser.locator's options slot, but Playwright ports writerow.locator(css), and Playwright's own options bag takeshas/hasText. The PR follows ENG-1211 (web only, nolocator()on the sharedLocator). Once this merges it becomes public API.
What
browser.locator(selector, { within })runs a CSS or XPath selector inside another locator, the way Playwright'swithin.locator(selector)does:withinis any locator from this test'sscreenorbrowser(filtered, positioned,or, or insideframeLocator), and the result stays in its frame. It is web only, as the ticket decided: the sharedLocatorgets nolocator(), anddeviceanddesktoptake nowithin. A frame'slocator()takes no options either, and now throwsINVALID_LOCATORfor a second argument instead of dropping awithin. A second argument that is not an options object now throwsINVALID_LOCATOR, so['td'].map(browser.locator), which passes the index, needsmap((selector) => browser.locator(selector)); the changeset says so.Two fixes ride along, each with its own changeset:
getByLabel(...)with a position and then a filter (.first().filter({ hasText })) lost the filter when used as a scope, ahas, or now awithin.e2e mcp'srun_code, ascreenlocator and abrowserlocator could not be combined (or,filter({ has }),dragTo,within):INVALID_LOCATOR.Why
Before this, a selector could not be scoped to a row except by writing one
>>chain or switching to agetBy*query, so Playwright, Cypress (.find), and Selenium (findElement) ports had to be rewritten by hand. Passing{ within }on main type-errors, and in JavaScript it is silently ignored: the selector searches the whole page.How it works
selectorexpression takes an optionalscope, the fieldqueryalready has (packages/core/src/engine/contract.ts:127). It already crosses the engine protocol as JSON, so the protocol does not change.EngineFixtureContext.expressionOf(api, locator)gives a fixture the expression behind a test's locator (packages/core/src/engine/index.ts:281,packages/core/src/run/fixtures.ts:563). It uses the ownership checkfilter({ has })andoruse, moved intoownedLocator(packages/core/src/locator/screen.ts:390), which now compares the engine session rather than the screen object.run_codebuilds its ownscreenover the attempt's session, so the old object check refused its locators next tobrowser's.browser.locatorchecks the options and mints{ kind: 'selector', selector, scope }(packages/web/src/browser.ts:866). The web engine projects it as Playwright'sscope.locator(selector)(packages/web/src/locators.ts:362), andframeSelectorsfollowsscopeso a framedwithinkeeps its frame (packages/web/src/locators.ts:427).packages/web/src/locators.ts:340).scopeinstead of silently matching the whole screen: core'sresolveExpressionruns the selector hook once over the scope's descendants (packages/core/src/engine/resolve.ts:210) andexpressionSelectorslists the scope's selectors, so an engine that queries them first, as Electron does, answers the scope too (packages/core/src/engine/resolve.ts:91); mobile's resolver does the same (packages/mobile/src/locate.ts:57), and desktop's query-kind guard walks into it (packages/desktop/src/surface.ts:186). Error messages readgetByRole("row", name: "Ada") >> locator("td.discount")(packages/core/src/locator/expression.ts:205).locator()refuses a second argument withINVALID_LOCATORand points tobrowser.locator(selector, { within })(packages/web/src/browser.ts:1427). No peer floor moves:@e2e-dev/webalready needs@e2e-dev/coreande2e>=0.25.1on main, the releaseexpressionOfships in.locatorentry inreference/web.mdx(semantics, order, that a>> nth=picks from the combined matches, throws, the closed shadow root limit, and that a frame'slocatortakes no options),reference/engine.mdx(scope,expressionOf,expressionSelectors), and the Playwright, Cypress, and Selenium guides, wherelocator.locator,.find('css'), andfindElementmove from the gap tables into the command maps. The consumer skill nameswithin.I checked the semantics against Playwright: matches come back once each in Playwright's order, scope match by scope match (with nested
withinmatches that is not document order::scope > .directunder nestedarticles returns the outer one'slatebefore the inner one'searly), a leading//,:scope, andxpath=..start at the scope element, and ahaslocator runs from each candidate, so a scope that is the candidate itself matches nothing.scoped-selectors.test.tsruns every case through the engine and Playwright on one page. One limit Playwright has no answer for: Playwright cannot see into a closed shadow root at all, and our reader can, soliandxpath=./liwork under awithinfound there, but a:scopecombinator on the root's direct child matches nothing. The docs say so.Overlap with open PRs: #1822 adds
context.withNode(api, locator, use)besideexpressionOfin the same files (expressionOftakes its argument order), a textual rebase. #1503 deleteslocators.ts; after it,splitFramesandselectorPartsneed to followscope, and the in-page resolver needs to run the selector under each scope match.scoped-selectors.test.tsis the check.Verified
Ran it locally: yes
withinon a row in the page and on a row in an iframe, thenfillandclickthrough it:browser.locator('td.price', { within: graceRow })withinignored: 2 matches,LOCATOR_AMBIGUOUS$9withina row inside an iframeLOCATOR_AMBIGUOUS$3in the framelocator matched no nodes within locator("td.discount")... within getByRole("row", name: "Ada") >> locator("td.discount")within: 'tr'(a string)INVALID_LOCATOR: browser.locator({ within }) requires an e2e locatorrun_code,mcp-run-code.test.ts, the new case with the ownership check as on main:INVALID_LOCATOR: or requires a locator made by this screen(and the same forwithin); passes here. Thewithinline counts*under the list, 3, so it fails with 58 when the scope is dropped.apps/testbed/tests/locator-query.e2e.ts, a Playwright port, rewrotediv.first().locator('p')as agetByTextscope; it now usesbrowser.locator('p', { within: browser.locator('div').first() })and passes 19/19.Gemini 4 Neon reviewed the design and the diff twice. Taken: the
run_codebug, the label bug, the closed-root:scopelimit (documented and pinned), test gaps. Declined: a protocol capability flag forscope(only the web fixture mints one and its engine ships in the same package; the contract says an engine must honor it). A runtime check on a frame'slocator()was declined then and added after two reviewers asked for it.expressionSelectorson{ selector: 'td.price', scope: tr with .grace }: main's walk returns['td.price'], so Electron never queries the scope and the locator matches nothing; the new case inresolve-expression.test.tsfails that way without the fix and returns['tr', '.grace', 'td.price']with it.scoped-selectors.test.tsaddsli >> nth=0under everyul, checked against Playwright: one element,a1.pnpm checkand the PR's suites on the rebased head: web 18, core/e2e 146, mobile 24, desktop 204, electron 253, all passing.pnpm bench:abon the web benchmark suite (no model calls): same steps and outcomes on both builds, no timing change.bench:ab table
bench-ab:
ea008c20(merge base with origin/main) vsdba811ffapps/web-benchmark:
e2e run --workers 1. 6 pairs in random order, resolved after 6 pairs. Threshold ±5% and 10 ms. darwin arm64, Apple M4 x10, Node 26.13.1, load 4.5.Behavior
Every test ran the same steps with the same outcome on every run of both builds.
Timings
Counters
Tests outside the threshold: 0 of 95
With 95 tests compared at 95%, about 4.8 could land outside by chance.
The docs change is entries and table rows on pages
pnpm docs:checkcompiles; no rendered screenshot.Written by Claude Opus 5.5 in Claude Code (T3 Code), reviewed by Gemini 4 Neon (Antigravity).
within.webm
Summary by CodeRabbit
New Features
Bug Fixes
Documentation