feat(web): read range widgets in toHaveValue

Closed
AS
19h ago
+298-11

What and why

  • toHaveValue reads a node's value, but the web reader set one only on native form controls, so an ARIA slider, spinbutton, progressbar, meter, or scrollbar, and a native <progress> or <meter>, could not be asserted on.
  • A locator read now gives those roles their aria-valuetext, else aria-valuenow, skipping a blank one. A native <progress> or <meter> with a value attribute then reads the value its range clamps it to, as Chrome does. A slider or spinbutton with none reads '', as before, any other widget with none has no value, and a stray value attribute on it is not read. A native value is computed from the value, min, and max attributes as HTML clamps them, never through .value, so a page's own getter (a customized built-in <progress is>) never runs; it equals Chrome's .value on 6,510 attribute combinations. Native form controls and editors read as before, a control adopted from another frame included.
  • locator.inputValue() reads the same field, so it returns these values too. Playwright's throws on an ARIA widget. I kept the two paired because the docs describe them together and mobile already works this way. If you'd rather keep inputValue() to form controls, that's a small follow-up here.
  • The agent's tree does not get this value, so what the model reads, the replay cache's evidence, and committed recordings do not change.
  • The MCP locate tool now prints a range widget's value too (value "50"), through the same redaction as any other value.
  • On iOS, nodes already carry an accessibility value outside the form roles (the captured trees show status "In progress" value="1"), so the matcher reads them today. Android drops the value of a non-editable node when it repeats the node's label, so that case uses toHaveText, and the Detox guide says so.
  • Docs: reference/expect.mdx, reference/screen.mdx, the Detox guide (a "Not yet" row now covers only that Android case), and the writing-tests skill line.

Issue

Part of #1855: expect(locator).toHaveValue('On'). @okwasniewski, this is ready for review.

Verified

Ran it locally: yes

  • to-have-value-widgets.test.ts runs the public locator and matcher on a real page: ARIA slider, aria-valuetext, spinbutton, progressbar, <progress>, <meter>, over-max and invalid native values, a blank ARIA value, an editable spinbutton, a native range input that keeps its own value, and widgets with no value that are still refused. It fails on main's web source and passes here.
  • A new case in read-node-checked.test.ts pins that the agent's tree still has no value for a range widget, and one in the mobile locate.test.ts pins the device projection, including the Android label echo.
  • pnpm check, the full pnpm test (8,082 passed), the testbed (598 passed, 3 skipped), and the web suite pass. A hostile-page audit (70 pages, 13 locator reads each) finds no read that works on main and fails here. Each clamp, the attribute parser, and the adopted-control guard fail a test when broken.
  • Not run on a device: no mobile code changed.

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: the docs/**/*.mdx page for the behavior, and skills/e2e/ if the skill describes it.
  • 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.