fix(electron): read progress values, empty-for labels, and text under aria-hidden or inert as web() does (ENG-892)

Merged
KD
20h ago
+56-12

What

The Electron engine reads four things the way web() does:

  • A <progress> or <meter> value is clamped to its range (value="25" max="10" reads 10). An indeterminate <progress> has no value, so toHaveValue('') and not.toHaveValue('') both fail on it.
  • A label with an empty for labels no control. A label with any for does not label a control it wraps. So a zero-size checkbox beside or inside such a label is hidden, not drawn by the label.
  • getByText finds text under an inert element, as it already found text under aria-hidden.
  • getByText under aria-hidden or inert answers with the element that holds the text (<span data-testid="north">North gate</span>), not only the element that hides it.

docs/electron.mdx also says that an element aria-owns names reads under its owner, so query results and first() order it there, not in document order. That order does not change.

Why

The second PR of the stack for the review of #2237 (ENG-892), which added @e2e-dev/electron. The review found these differences from the web engine in what the tree reads:

  • rangeValueOf read a native element's value attribute as written: 25 for value="25" max="10", and '' for an indeterminate progress bar, which has no value on the web.
  • drawnByLabel took a label with for="" as the label of an element with no id, and a wrapping label with a for as the label of the control it wraps. A hidden control next to such a label read as visible.
  • placeAbsent placed only the element that carries aria-hidden="true". Text under inert was not found, and text in a child of a hiding element was found only on the hiding element.

The aria-owns order is Chromium's tree order. We decided to document it and not change it.

How it works

  1. rangeValueOf (packages/electron/src/fields.ts:208) reads aria-valuetext, then aria-valuenow, as written. Without them, a PROGRESS or METER element with a value attribute reads Chromium's value for it (node.value), which is clamped. Else a slider or spinbutton reads '', and any other range role, an indeterminate progress bar too, has no value.
  2. drawnByLabel (packages/electron/src/snapshot.ts:182) looks up labels by for only for an element with a non-empty id. A label around the element counts only when it has no for attribute (snapshot.ts:184), as label.control reads it.
  3. placeAbsent (packages/electron/src/tree.ts:201) collects every element with aria-hidden="true" or inert, then places every element with bounds that is one of them or under one (tree.ts:212). A page with no such element is not walked. Text nodes are left out: their text folds into the element that holds them, so a text query answers with that element. These nodes have no role, so a role query still does not find them.
  4. docs/electron.mdx:268 adds the aria-owns row to "What differs from the web".
  5. The testbed's controls page gets the cases (apps/electron-testbed/app/controls.html), with assertions in apps/electron-testbed/tests/controls.e2e.ts.

Issue

Part of ENG-892. Stack: #2419 → this PR → #2421 → #2422 → #2423.

Verified

Ran it locally: yes

  • pnpm --filter @e2e-dev/electron test and test:integration, and the electron testbed, on this layer:
@e2e-dev/electron unit + integration: Tests  147 passed (147)
apps/electron-testbed:                Tests  75 passed (75)
  • The testbed tests of this PR on the code of the PR below it (the bug) and on this PR (the fix):
TestPR belowthis PR
testbed controls.e2e.ts: reads a heading tag's level over its aria-level, and a progress element's valuefailedpassed
testbed controls.e2e.ts: checks a checkbox its label draws, and finds text by text alone, as web() doesfailedpassed
testbed controls.e2e.ts: finds text that inline markup splits, and text under aria-hidden or inert, as web() doesfailedpassed
  • Behavior and timing against main: see the pnpm bench:ab table in #2423.
  • No changeset: @e2e-dev/electron is not released yet (0.0.0, not on npm).

šŸ¤– Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Progress indicators now clamp determinate values to their maximum; indeterminate indicators are no longer mistaken for empty or populated ones.
    • Label-based control matching ignores labels that do not identify the control. Text queries handle inert content more accurately.
    • Accessibility queries better reflect range values and account for elements hidden with aria-hidden or inert.
  • Documentation
    • Clarified how aria-owns affects accessibility-tree reading order and query results.