fix(core)!: match getByText against the text a node shows

Merged
OK
21h ago
+375-41

What

Breaking. On the mobile and desktop engines getByText matches the text a node shows. It matches the accessible name only for a node that shows no text (text omitted, empty, or whitespace), such as an icon button.

// a status bar: static text "Words" beside a static text "5" named "Words"
await expect(screen.getByText('Words')).toHaveText('Words'); // was LOCATOR_AMBIGUOUS
await expect(screen.getByText('5')).toHaveAccessibleName('Words');
await expect(screen.getByLabel('Words')).toHaveCount(2);

What stops working: getByText(name) for a node that shows other text. Use getByLabel(name), or the text the node shows.

NodegetByText beforegetByText now
Android text with a content description (<Text accessibilityLabel="Total price">$5</Text>)Total price or $5$5
Android filled field with a descriptiondescription or contentcontent
Android empty field with a description (Key echo field, hint Key echo)description or hinthint
iOS nodeits one labelunchanged
macOS text fieldits nameunchanged, a field has no text of its own
macOS text named otherwise (5 named Words)Words or 55

filter({ hasText }) is unchanged: it reads names, text, and values. So getByRole('text').filter({ hasText: 'Words' }) keeps the 5 that getByText('Words') skips. The JSDoc and docs/reference/screen.mdx say so.

Why

A text query matched a node's name or its text. A value named by the label beside it (a status bar's Words next to a 5 whose accessible name is Words) made getByText('Words') return both nodes. The web engine never did this: getByText there reads text content, not aria-label. docs/reference/mobile.mdx already says an Android text with a content description answers getByLabel by the description and getByText by what it shows.

Decisions

Made by the review agent on Oskar's behalf. Flip either one if you disagree.

  • The name fallback stays for a node with no text of its own, and blank text counts as none. Not text-only: an icon button would stop answering getByText.
  • Released as breaking under CONTRIBUTING.md "Stability policy": a fixture's runtime behavior and an exported @e2e-dev/core/engine function change. The changeset is minor for @e2e-dev/core, e2e, @e2e-dev/mobile, @e2e-dev/desktop, patch for @e2e-dev/web and @e2e-dev/electron (engine contract rule: every engine ships in the joint release; no behavior change in either), and the title carries !. There is no deprecation window: the old match is the bug. Oskar confirmed this on 2026-11-28: no window, it ships in the 0.26.0 minor.
  • Peer floors assume this PR ships in the next release cut from main, which is 0.26.0: npm latest is 0.25.0, and the pending changesets on main already make the next @e2e-dev/core and e2e 0.26.0 (the open version PR, built from main without this change, says so). @e2e-dev/mobile and @e2e-dev/desktop therefore need >=0.26.0. If 0.26.0 is published before this merges, raise both floors to the release that does carry shownText.

How it works

  1. shownText(node) is the one rule: text, or name when text is omitted or blank. Exported from @e2e-dev/core/engine (packages/core/src/engine/resolve.ts:47). resolveExpression and the mobile engine's matcher (packages/mobile/src/locate.ts:156) both call it.
  2. Desktop rows and cells. The driver names a row, cell, tree item, option, or list item by the names of the texts inside it, and the projection showed that name as its text. A cell holding a 5 named Words then matched getByText('Words') in place of its child. The projection now reads the text of such a node from the texts inside it (contentText, packages/desktop/src/nodes.ts:239). A heading with no text of its own gives the text under it. A row on screen leaves out the text inside it that is off screen, hidden, or collapsed to no size, so getByText('Archived', { visible: true }) does not answer with a visible row whose Archived is scrolled out; a row that is itself hidden keeps all its text, which is what a query finds it by to scroll to. The name is unchanged, so getByRole('row', name) behaves as before, and selectOption(label) too: the driver matches an option by its name and never reads this text. textContent() of a row reads the same shown text.
  3. Desktop headings. A web view reports a heading's level as a numeric AXValue and its text as AXTitle. The driver reads a heading's number as its level and never as its text (shown_value, crates/e2e-desktop-napi/src/snapshot.rs:245), so the heading no longer shows 2 as text, and getByRole('heading', { level }) works in a web view that has no AXHeadingLevel. The earlier special case in the projection is gone: a native heading with a text value keeps that text.
  4. @e2e-dev/mobile and @e2e-dev/desktop raise their peer floors on @e2e-dev/core and e2e to >=0.26.0, the first release with shownText (see Decisions). An older core has no shownText for the mobile engine to import, and its resolver leaves the desktop Words case ambiguous.
  5. The desktop testbed's Controls window gets the label and value pair, and a test for it (apps/desktop-testbed/app/macos/main.swift, apps/desktop-testbed/tests/controls.e2e.ts).
  6. docs/reference/screen.mdx (getByText, filter) and docs/reference/engine.mdx (resolveExpression, shownText) state the rule, what a field shows per platform, and that a browser engine reads text content only.

Left as is:

  • The MCP line search still tries getByText(name) as a candidate (packages/e2e/src/session-tools/test-lines.ts). A candidate that does not resolve to the node is rejected.
  • A desktop container that is not a row or cell (a group an app names Words around a 5) shows no text of its own, so its name still answers getByText('Words'). Same for a macOS text field beside a visible label. Both follow from the fallback kept above.
  • A visible desktop row with no name of its own and none of its text on screen shows no text, so the name the driver builds from that text stands in, as on main. A text query cannot tell that name from one the app gave.
  • selectOption(label) on a desktop table matches a row's name, built from the names of its texts, not from what they show.

Main gained a textQuery option on resolveExpression while this PR was open (the Electron engine sets 'text'). 'text' is unchanged: it reads the text alone. The default, 'nameOrText', now reads what a node shows (shownText). The Electron engine's unit tests pass unchanged (97).

Issue

From kdy1's desktop engine findings (finding 11b). No Linear ticket id on the title: no Linear access in this session.

Verified

Ran it locally: yes

  • Desktop testbed in background mode, native driver built from this head: node node_modules/e2e/dist/cli/bin.js run in apps/desktop-testbed, 26 passed, among them the Words pair and the existing row and cell text test. After the hidden-text and heading fix: tests/controls.e2e.ts, 17 of 18 passed, and the context menu test (its menu was closed under it on a shared machine) passed when run again alone.
mainthis PR
LOCATOR_AMBIGUOUS: locator matched 2 nodes, expected exactly one: getByText("Words")passes
  • Web view heading, live: a scratch AppKit app with a WKWebView (<h2>Settings</h2>), read through the accessibility API and then through the rebuilt driver.
raw:    AXHeading AXTitle=Settings AXValue=2 <__NSCFNumber>   (no AXHeadingLevel)
driver: heading {"name":"Settings","level":2}                  (no value)
  • Hidden row text and a heading with no text: scripted snapshots in packages/desktop/tests/unit/nodes.test.ts. Both new tests fail on the previous head (getByText('Archived', { visible: true }) answered with the row; exact Settings Badge found nothing). Not run against a live table.
  • Peer floors: pnpm check accepts the ranges. A packaged install at 0.26.0 is not possible yet: it is not published.
  • Table cell: a scripted snapshot (label Words, then a row with a cell holding 5 named Words). Before the fix getByText('Words') returned the label and the cell; now the label alone. Not run against a live table with a named cell text.
  • Mobile: recorded snapshots only, no simulator or emulator. packages/mobile/tests/unit/locate.test.ts reads control-inventory.json from Android (Inventory heading, Name field, Key echo field) and iOS (Name field).
  • The new core and mobile tests fail when the rule is reverted (blank text read as text; name-or-text in the mobile matcher).
  • pnpm build, pnpm check, unit tests of @e2e-dev/core (130), e2e (5056), @e2e-dev/mobile (708), @e2e-dev/desktop (250); cargo fmt, cargo clippy -D warnings, cargo test (58).
  • Not verified: a Chromium or Electron web view (WebKit only), and Windows or Linux, which the desktop engine does not run on.
  • No video: the change is which node a query returns. Docs screenshots: not taken, reference text only.