fix(desktop): check a pressed control's focus by its element
What
locator.press and typed text no longer fail with did not keep keyboard focus on a control whose box changes as it takes focus, when nothing names it apart from its siblings. Each press also reads the window one time less.
Why
Reported on Google's search box in Chrome: fill, then press('Enter'), failed with
ACTION_FAILED: node n897 did not keep keyboard focus, so the key would land on another control
After focusing the control, the engine read the whole window again and looked for the control among the focused nodes. A control with a look-alike sibling or ancestor has no stable id, so it was matched by role, name, test id, twin count, and rect (sameNode). The search box grows when it takes focus (415 to 535 points wide), so the match failed though the control held focus. In web content almost every node sits under look-alike groups; a native search field that expands on focus beside a twin fails the same way.
The driver already checks focus by the element itself right before the key goes, so the TypeScript check could only add false refusals.
How it works
perform's press case no longer callsholdsFocus;sendKeypasses the control's ref asfocusedRef, and the driver refuses the key unless the app'sAXFocusedUIElementis that element (crates/e2e-desktop-napi/src/actions/mod.rs,press). That check was already there.typeTextwith replace drops its twoholdsFocuscalls: the delete goes throughsendKeywithfocusedRef, and the driver'stype_textrefuses when the field's element is not the focused one and never focuses it back (crates/e2e-desktop-napi/src/actions/typing.rs).holdsFocusis deleted (packages/desktop/src/surface.ts).sameNodestays for hover and double-click on a node with no ref.- Unit tests that scripted lost focus through a second snapshot now script the driver's refusal. The tests for look-alike twins swapping places are gone with the snapshot matching they covered: an element reference cannot pass to a twin.
afterChange, which marks a failure after an earlier command of the step as possibly committed, names the failed command once. On main it put its label in front of a message that already had it:click: click: ...for a tap after a scroll,type: type timed out ...for a type after a clear. Only the driver's own failure, which carries no label, gets one now. Two state errors pass through without a command name, as they read everywhere else:the app is not running; open it with app.open()andthe desktop engine is not initialized.
Issue
From kdy1's desktop engine findings of 2026-11-27 (finding 10).
Verified
Ran it locally: yes
- Desktop testbed, new case: two
Tagfields with the same label, each growing from 80 to 160 points as it takes the keyboard;press('x'), thenpress('Enter'), on the first.
| main | this PR |
|---|---|
ACTION_FAILED: node n1548 did not keep keyboard focus, so the key would land on another control | passes, status reads Submitted: x |
- Second new case: a field that hands the keyboard to another as it is focused;
press('x')is refused and the other field stays empty. The driver'sfocusstep catches that hand-off (12 of 12 runs:focus: the element did not take keyboard focus, after about 1 s). - The driver's check right before the key has no test in the suite. Through
locator.pressit fires only when focus moves after the driver confirmed it and before the key, and the app sees nothing between the two to react to, so a testbed control could only do it on a timer. Run once against the testbed app with the native driver called directly: focus Username, focus Password,presswithfocusedRefof Username answersACTION_FAILED,not_delivered,the control lost keyboard focus before the key was sent, so nothing was sent, and both fields stay empty. - Unit tests pin the wording of point 5: a click after a scroll, a refused delete, a type the driver refused after a clear, and a type that times out after a clear each name their command once. With main's
afterChangeput back, the click, the delete and the timeout cases fail. - Background suite 27 passed (run again on the final commit, controls file three more times); headed suite 5 passed on the first commit, not run again.
- Google Chrome with
--force-renderer-accessibility,desktop({ headed: true, maxDepth: 50 }), google.com:fill('best headphones')thenpress('Enter')failed on main with the reported error and passes here; the results page loads. pnpm bench:abhas no desktop suite. A press now makes one snapshot fewer; on a 1,000-node window a snapshot was measured at about 1.1 s earlier this week.
Checklist
- Changeset added
- Docs: no page describes the removed check