Skip to content

fix(web): report a selector the engine cannot parse as INVALID_LOCATOR - #2121

Merged
okwasniewski merged 1 commit into
e2e-inc:mainfrom
DeryFerd:fix/web-malformed-selector-invalid-locator
Nov 23, 2026
Merged

okwasniewski merged 1 commit into
e2e-inc:mainfrom
DeryFerd:fix/web-malformed-selector-invalid-locator

Conversation

@DeryFerd

@DeryFerd DeryFerd commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What

A selector the engine cannot parse now fails as INVALID_LOCATOR (category test, exit 1), through locate, count(), an action, or expect(...), instead of ENGINE_FAILURE (infrastructure, exit 3).

Why

Playwright parses a selector lazily, inside the call that first uses it, so button[type="submit", xpath=//[, nope=x, div >>, and text=/(/ arrive as ordinary errors. translatePwError and classifyActionError passed those to their ENGINE_FAILURE fallback, so a typo in test code read as an engine fault and an agent treated it as retryable infrastructure. The taxonomy already has the right code for it, and issue #2040 lists the forms a page's own tests can produce.

How it works

  1. isSelectorParseError in packages/web/src/support.ts matches two groups of messages, taken from Playwright 1.65.1: Playwright's own while parsing selector and while parsing css selector and Malformed selector: (the unknown-engine message already contains the first), and, only when Playwright's locator.<call>: prefix is there, the browser's is not a valid XPath expression and JavaScript's Invalid regular expression for xpath=//[ and text=/(/. The prefix keeps an unrelated XPath or regex failure outside a locator call an engine fault, and a test pins that.
  2. translatePwError (packages/web/src/support.ts:371) returns new TestError('INVALID_LOCATOR', ...) with the raw error as its cause ahead of the ENGINE_FAILURE fallback. Surface.guard wraps every operation with this translator by default, so locate, navigation, artifact calls, and the expect tier all reach it.
  3. staleOr checks the selector before STALE_PATTERN, so a locate on a selector whose text happens to contain "not found" is still a test-code mistake and not NODE_STALE.
  4. classifyActionError in packages/web/src/actions.ts:506 decides the selector right after isClassified, before every message-shaped branch, so an action whose selector text contains "not found" or "not editable" is not read as stale or unactionable. The cause it attaches is the same sensitive-aware variable the other branches use, so a secret fill still drops the raw Playwright error.
  5. ENGINE_ERROR_CODES stays closed: a TestError crosses the engine protocol as a type-e2e error (packages/core/src/engine/protocol/protocol.ts), so a remote engine keeps INVALID_LOCATOR and its test category without adding a code to the engine set.
  6. docs/reference/errors.mdx extends the INVALID_LOCATOR row with the selector forms, and the mapping table comment in support.ts gains the row.

Issue

Fixes #2040

Verified

Ran it locally: yes

  • pnpm --filter @e2e-dev/web exec vitest run tests/unit/errors.test.ts tests/unit/actions.test.ts, first with packages/web/src/support.ts and actions.ts restored to main and the new tests in place, then with the branch. On main the two new tests fail with ENGINE_FAILURE; here all 71 pass.
  • The five selector forms in the tests come from the installed Playwright, not from guessing, captured with page.locator(sel).count() on a blank page.
main this PR
translatePwError(new Error('... while parsing selector ...'), 'locate') returns ENGINE_FAILURE, category infrastructure INVALID_LOCATOR, category test, cause kept
classifyActionError on the same message returns ENGINE_FAILURE INVALID_LOCATOR, category test, cause kept
staleOr on a parse error containing "not found" returns NODE_STALE, retryable INVALID_LOCATOR, not retried
"button[" => "locator.count: Unexpected token \"\" while parsing css selector \"button[\". Did you mean to CSS.escape it?"
"xpath=//[" => "locator.count: SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//[' is not a valid XPath expression."
"nope=x" => "locator.count: Unknown engine \"nope\" while parsing selector nope=x"
"div >>" => "locator.count: Unexpected token \"\" while parsing css selector \"\"."
"text=/(/" => "locator.count: SyntaxError: Invalid regular expression: /(/: Unterminated group"
AssertionError: expected EngineError: locate failed: locator.evalu... { ...(2) } to match object { code: 'INVALID_LOCATOR', ...(1) }
Tests  2 failed | 66 passed (68)
Tests  71 passed (71)
  • pnpm --filter @e2e-dev/web run typecheck and oxlint on the four changed files: clean.
  • Not benchmarked: the branch runs only on a selector parse failure, which no passing step reaches.
  • The message keeps Playwright's parse line, including the internal >> e2e-read=... selector that locate appends. Only the code, the category, and the cause change.

Checklist

  • Changeset added (pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only.
  • Breaking change: title carries !, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md).
  • Docs updated in the same PR: docs/reference/errors.mdx. The skill's debugging reference groups INVALID_LOCATOR with INVALID_ARGUMENT as a step-argument failure, which stays true.
  • Contract change: emitted .d.ts reviewed, tests/types/sdk-types.ts updated; wire change edits the schema and both fixtures.
  • Engine contract change (e2e/engine): changesets for e2e, @e2e-dev/web, and @e2e-dev/mobile.

@github-actions github-actions Bot added the size:S Up to 29 changed lines, not counting tests, fixtures, translated docs, or the lockfile label Nov 23, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 6 files

Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.

View guided diff | Re-trigger cubic

Comment thread docs/reference/errors.mdx Resolved
Comment thread packages/web/src/actions.ts Resolved
Comment thread packages/web/src/actions.ts Resolved
@DeryFerd
DeryFerd force-pushed the fix/web-malformed-selector-invalid-locator branch from e5879b9 to ca58a2a Compare November 23, 2026 16:18
@github-actions github-actions Bot added size:M Up to 99 changed lines, not counting tests, fixtures, translated docs, or the lockfile and removed size:S Up to 29 changed lines, not counting tests, fixtures, translated docs, or the lockfile labels Nov 23, 2026
@DeryFerd

Copy link
Copy Markdown
Contributor Author

All four inline threads are addressed and resolved: the XPath and regex forms now have tests with the messages Playwright 1.65.1 emits, the selector check runs before the stale and unactionable branches, the raw cause is attached, and the changeset says exit 1.

@okwasniewski okwasniewski left a comment

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.

[claude-opus-5-5] automated review on behalf of @okwasniewski

Re-checked ca58a2a (amended after our first read of e5879b9) against main e486fbd, using real Playwright 1.65.1 messages for each selector form in #2040.

Every code ask from the first read is done:

  • The parse check now runs first in staleOr and classifyActionError, so div:has-text("not found" no longer becomes a retryable NODE_STALE, and not editable no longer becomes NOT_ACTIONABLE. Both cases have tests.
  • xpath=//[ and text=/(/ are now matched by their real messages, with a test for each, so the docs row and the changeset are accurate.
  • The changeset says exit 1.
  • { cause } is kept in translatePwError and classifyActionError, and dropped for sensitive fills.

Hold: maintainer decision. Classifying Playwright errors by message text was the open question in #2040, and it is still unanswered. Playwright throws a plain Error for all of these and exposes no code or public parser, so on the current driver text is the only signal. The WebDriver BiDi driver (#1503) deletes support.ts and reports this case from structured data (pageParts refuses unknown engines, the in-page query returns unparsedSelector). So this PR only matters until #1503 lands.

Should fix

  • packages/web/src/support.ts:389 Invalid regular expression and is not a valid XPath expression are generic browser/JS messages. Today they only reach this pattern through engine calls (evaluate has its own path), so the risk is small. Still, matching the locator. call prefix Playwright puts on them would keep a future caller from turning an unrelated error into INVALID_LOCATOR.
  • Unknown engine " is redundant: Playwright's unknown-engine message already contains while parsing selector.

Nits

  • The changeset has no trailing newline.

Verified at e5879b9: vitest run tests/unit/errors.test.ts tests/unit/actions.test.ts passes, and a mutant (isSelectorParseError returns false) fails both new tests. The real messages for every #2040 form went through staleOr, translatePwError and classifyActionError. The delta to ca58a2a adds exactly the ordering, phrases, tests and cause asked for.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

0 issues found across 5 files (changes from recent commits).

Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.

View guided diff | Re-trigger cubic

Playwright parses a selector lazily, so a malformed CSS selector, a bad
xpath=/text=, a stray >>, or an unknown engine name surfaced through
translatePwError as an infrastructure ENGINE_FAILURE (exit 3), and an
agent read it as retryable infrastructure instead of a test-code typo.

The shared translator and the action classifier now recognise
Playwright's parse failure and return INVALID_LOCATOR (test, exit 2).

Closes e2e-inc#2040
@DeryFerd
DeryFerd force-pushed the fix/web-malformed-selector-invalid-locator branch from ca58a2a to b9a183b Compare November 23, 2026 16:29
@DeryFerd

Copy link
Copy Markdown
Contributor Author

@okwasniewski both should-fixes are in at b9a183b: the generic is not a valid XPath expression and Invalid regular expression messages now require Playwright's locator.<call>: prefix, with a test that an unprefixed one stays ENGINE_FAILURE; Unknown engine " is gone because its message already contains while parsing selector; the changeset has a trailing newline. 71 tests pass, typecheck and oxlint clean. Understood on the hold: I will not merge or press for the message-text decision. The ordering and phrase work lands either way, and #1503 can replace the matching when it arrives.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

0 issues found across 3 files (changes from recent commits).

Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.

View guided diff | Re-trigger cubic

@okwasniewski okwasniewski left a comment

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.

[claude-opus-5-5] automated review on behalf of @okwasniewski

Re-checked b9a183b: both should-fixes are done. The XPath and regex phrases now only match behind Playwright's locator.<call>: prefix (LOCATOR_EXPRESSION_PARSE_PATTERN), with tests, and the redundant Unknown engine " alternative is gone. The changeset has its trailing newline. No code asks left.

The one red check (test (24), packages/moli "stops descendants when the wrapper exits before release") is an unrelated process-teardown flake, rerun.

Still held on the #2040 maintainer decision: accept message matching until #1503's structured unparsedSelector path replaces it, or close as superseded by #1503.

@okwasniewski okwasniewski added the Ready for Human Review Green, conflict-free, every thread handled. Waiting on a maintainer. label Nov 23, 2026
@okwasniewski
okwasniewski merged commit 0007636 into e2e-inc:main Nov 23, 2026
43 of 45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for Human Review Green, conflict-free, every thread handled. Waiting on a maintainer. size:M Up to 99 changed lines, not counting tests, fixtures, translated docs, or the lockfile

Projects

None yet

Development

Successfully merging this pull request may close these issues.

web: a malformed selector is ENGINE_FAILURE (exit 3) instead of INVALID_LOCATOR

2 participants