Skip to content

chore(locators): rewrite locator parser with per-language parsers - #42895

Merged
Yury Semikhatsky (yury-s) merged 4 commits into
microsoft:mainfrom
yury-s:locator-parser-rewrite
Sep 24, 2026
Merged

Yury Semikhatsky (yury-s) merged 4 commits into
microsoft:mainfrom
yury-s:locator-parser-rewrite

Conversation

@yury-s

@yury-s Yury Semikhatsky (yury-s) commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Replace the regex-based locator parser with a tokenizer and a recursive descent parser per language (JS, Python, Java, C#) that produces a ParsedSelector directly; each language maps its method names to shared call handlers.
  • The parser validates methods, arguments and options itself, so the round-trip check through asLocators is removed. Also parses and(), or() and locator(locator).
  • Support multiple regex flags (i, m, s) in Python, Java and C# locators; the generators no longer drop m and s.
  • Redundant engine prefixes are normalized, e.g. locator('css=.foo') now yields .foo.

References #42891

Replace regex-based template rewriting with a tokenizer, a recursive
descent parser per language producing language-neutral calls, and a
shared selector builder. Also parses and(), or() and locator(locator).
Comment thread packages/isomorphic/locatorParser.ts Outdated
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Map each language's method names to call handlers that produce
selector parts, and pass the ParsedSelector to asLocators directly.
Support multiple regex flags in Python, Java and C# locators.
The parser validates methods, arguments and options itself, so the
selector no longer needs to be rendered back and compared to the input.
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

Test results for "tests 1"

7 flaky ⚠️ [chromium-library] › library/browsercontext-page-event.spec.ts:160 › should work with Shift-clicking `@chromium-ubuntu-22.04-arm-node20`
⚠️ [chromium-library] › library/browsercontext-page-event.spec.ts:173 › should work with Ctrl-clicking `@chromium-ubuntu-22.04-arm-node20`
⚠️ [chromium-library] › library/popup.spec.ts:260 › should not throw when click closes popup `@chromium-ubuntu-22.04-node24`
⚠️ [chromium-library] › library/chromium/chromium.spec.ts:179 › serviceWorker(), and fromServiceWorker() work `@chromium-ubuntu-22.04-node20`
⚠️ [chromium-library] › library/video.spec.ts:762 › screencast › should work with video+trace `@chromium-ubuntu-22.04-node20`
⚠️ [firefox-library] › library/browsercontext-cookies-third-party.spec.ts:257 › third party 'Partitioned;' cookies `@firefox-ubuntu-22.04-node20`
⚠️ [firefox-library] › library/browsercontext-cookies-third-party.spec.ts:470 › top level 'Partitioned;' cookie and same origin iframe `@firefox-ubuntu-22.04-node20`

52181 passed, 1241 skipped


Merge workflow run.

@github-actions

Copy link
Copy Markdown
Contributor

Test results for "MCP"

2 failed
❌ [firefox] › mcp/http.spec.ts:105 › http transport browser lifecycle (isolated) @mcp-ubuntu-latest-firefox
❌ [firefox] › mcp/cli-core.spec.ts:57 › click link @mcp-windows-latest-firefox

8703 passed, 1474 skipped


Merge workflow run.

@github-actions

Copy link
Copy Markdown
Contributor

Hi, I'm the Playwright bot and I took a look at the failing CI runs here.

🟢 Both failures are pre-existing Firefox MCP flakes — the PR is clear

mcp/http.spec.ts:105 and mcp/cli-core.spec.ts:57 both fail on Firefox regularly on main and on unrelated PRs, with the exact same errors.

Details

This PR only touches packages/isomorphic/locatorParser.ts / locatorGenerators.ts and tests/library/locator-generator.spec.ts. The locator parser is consumed by the recorder and trace viewer to turn locator source text into a selector; neither failing MCP test parses locator strings, and nothing in the diff is Firefox-specific. The "tests 1" report is green (52181 passed, 7 flaky, 0 failed).

Pre-existing flake / infra

Caveat, as always: this is a statistical argument, not a proof. A rerun of the MCP job should come back green.

Triaged by the Playwright bot - agent run

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