feat(mobile): type into the focused field and press Backspace (ENG-1246)

KD
13h ago
+468-56

What

A mobile test can now type into the focused field and press Backspace without a locator:

await screen.getByTestId('email-input').tap();
await device.keyboard.type('jane@example.co');
await device.keyboard.press('Backspace');
await device.keyboard.press('Enter');
  • device.keyboard.type(text) and device.keyboard.press(key) send input to the field that has focus. Each call is a device.keyboard.* step. The type step shows only the length of the text (7 chars), and so does a press of a character; a named key such as Enter shows its name.
  • press('Backspace') now works on iOS and Android, both on a field's locator and on the focused field. Before this change it failed with UNSUPPORTED_CAPABILITY.
  • Backspace fails with UNSUPPORTED_CAPABILITY in two cases. The first is a control that is not an enabled, editable text field. The second is an Android device leased from BrowserStack, TestMu AI, or Revyl.
  • Tab, other named keys, modifiers, and Android key codes still fail with UNSUPPORTED_CAPABILITY. They moved to ENG-1525.

Why

Tests migrated from Maestro (inputText and pressKey with no selector, eraseText: N), Appium (driver.keys, getActiveElement().sendKeys(), pressKeyCode(67)), and Detox (tapBackspaceKey()) had no way to do these actions. The Maestro, Appium, and Detox migration guides listed them as gaps. This change adds the parts that agent-device can already send. isKeyboardShown was already available as device.isKeyboardShown().

How it works

  1. softKey() maps one key of the core key grammar to what agent-device can send (packages/mobile/src/keyboard.ts:186):

    • Enter goes to command.keyboard({ action: 'enter' }).
    • Space and a single character are typed as text.
    • Backspace is typed as \b. agent-device turns \b into the delete key: XCUITest on iOS and KEYCODE_DEL on Android. Its own Maestro eraseText uses the same text.
    • Every other key throws before anything is sent.

    The locator press and the focused-field press each had their own copy of the parsing in surface.ts. Both now call softKey(), which lives in keyboard.ts with typesIntoNode, describeField, and sendSoftKey, so surface.ts ends up 8 lines shorter than on main.

  2. AgentDeviceSurface.softKey refuses Backspace on Android when the slot's lease comes from BrowserStack, TestMu AI, or Revyl (NO_ADB_TEXT_PROVIDERS, packages/mobile/src/surface.ts:1791). These providers take text through their own backend: WebDriver for BrowserStack and TestMu AI, which types \b as a character instead of deleting. Limrun keeps Backspace, because agent-device drives its Android instances over its own adb backend. iOS keeps Backspace on BrowserStack and TestMu AI, where XCUITest takes the \b. Revyl enters text only at a point, so typing into the focused field already failed there on both platforms. On Revyl iOS, Backspace fails the same way: @agent-device/revyl refuses the typed \b. The Revyl page and the keyboard throws table say so.

  3. pressKey taps an unfocused text field first (surface.ts:1817). typesIntoNode decides what a text field is (keyboard.ts:214): a textbox, a searchbox, or a combobox that the platform reports as editable. Before this change, only a textbox got the tap, so Enter and characters on an unfocused search field or editable combo box now tap it first too. The changeset says so. Backspace also needs the field to be neither disabled nor read-only. Otherwise the tap leaves focus where it was, and the delete would go to the field that still has focus.

  4. device.keyboard (packages/mobile/src/device.ts:309, :514) checks its argument and then runs the existing typeText and pressFocusedKey paths with the action budget. Both calls count as actions for transition. The press label keeps a named key and shows a character, or a string that is no key, by its length (pressLabel), so a run of single presses never spells a value into the report. Its INVALID_ARGUMENT message gives the length too. The labels show the argument's type when the argument is not a string, because the recorder builds the label before the method checks the argument.

  5. Docs:

    • docs/reference/mobile.mdx has a new keyboard entry.
    • In the Maestro, Appium, and Detox guides, these rows moved from Planned to mappings. eraseText: N maps to pressing Backspace N times. A bare eraseText erases up to 50 characters, so the guide no longer maps it to .clear(). The Detox and Maestro Backspace rows name the cloud devices where Backspace fails and keep .fill() with the shorter text for them.
    • The BrowserStack and TestMu AI pages list the Android Backspace limit, and the Revyl page lists Backspace on both platforms. The Appium rows, the package README, and the skills/e2e setup reference name the same limits.
    • The transition entry lists keyboard.type and keyboard.press among the device calls that count as actions.
    • The skills/e2e setup reference says which keys a device accepts.
  6. Tests:

    • Unit tests cover each key's agent-device call, the refusals, the lease case on both platforms and for Limrun Android, and the label and argument edge cases.
    • The mobile type tests pin both signatures.
    • The mobile benchmark's Control Inventory gets a test for device.keyboard and Backspace (apps/mobile-benchmark/tests/controls.e2e.ts:96). The refusal test now also checks Tab.

Issue

Resolves ENG-1246. ENG-1525 tracks Tab and key codes, which need a key event API in agent-device.

Verified

Ran it locally: yes

  • I ran the mobile benchmark with the built CLI on an iPhone 17 Pro simulator, using a Release build of the benchmark app: e2e run tests/controls.e2e.ts --target ios-simulator --video --grep "keyboard|press|refused|reopen". All 7 tests passed. The steps of the new test:
passed  locator.tap getByTestId("key-input")
passed  device.keyboard.type 3 chars
passed  expect.toHaveValue getByTestId("key-input")
passed  device.keyboard.press Backspace
passed  expect.toHaveValue getByTestId("key-input")
passed  locator.press getByTestId("key-input")
passed  expect.toHaveValue getByTestId("key-input")
passed  device.keyboard.press Enter
passed  expect.toHaveText getByTestId("key-status")
  • I also ran a scratch project against the Settings search field on the iOS simulator and on an Android 16 emulator (e2e_api36). On both, the value went general → gener → gene → genea (Backspace twice, then a and Space). press('Tab') failed with UNSUPPORTED_CAPABILITY: agent-device cannot press Tab on a device surface; only Enter, Space, Backspace, and single characters reach the soft keyboard.
  • After the rebase onto main, the @e2e-dev/mobile tests (740) and pnpm check pass. Main had added device.pressButton, device.lock(), getAttribute on device nodes, scrollTo, and a docs restructure. The device runs above were made before the rebase. The conflicts were in docs lines that both sides edited, in one import line of device.ts, and next to pressKey in surface.ts, where scrollTo added its helpers. CI runs the mobile benchmark on both platforms again.
  • Not run: a BrowserStack, TestMu AI, or Revyl device. The Android lease refusal is covered by packages/mobile/tests/unit/provider.test.ts. Backspace on BrowserStack and TestMu AI iOS, and the Revyl iOS failure, come from reading agent-device's code, not from a run.
  • Three fresh-context review rounds ran, and their findings are fixed. Two points were left out on purpose:
    • Reading focus back after the focusing tap. A character press has the same gap on main, and the check would cost one snapshot per key. Disabled and read-only fields, the cases the tree reports, are refused.
    • Refusing Backspace before the tap on Revyl iOS. The tap only focuses the field, so nothing is deleted, and a character press on Revyl iOS fails the same way on main. The Revyl page now names Backspace.

pnpm bench:ab ran on an iOS simulator with the tests that use key presses: the controls press, keyboard, and refusal tests, and the login form. Head was 355395d2, before the rebase onto main. The later commits change only which fields press taps first and where Backspace is allowed, move the key helpers into keyboard.ts, keep Backspace on Limrun Android, change the keyboard.press step label for characters, and add tests and docs. No benchmark test presses a searchbox, a combobox, or a disabled or read-only field.

  • signs in and logs out failed in every run on both base and head. It fails the same way on main, so this change is not the cause. The local runtime is iOS 27.2, and CI pins iOS 26.5. I did not look into it further. It stays in the timing rows because both sides behave the same.
  • The behavior section lists the new test and the added Tab refusal step. The restart test timed out on app.open once on head, under a load average of 10 to 60 from other sessions on this machine. That is also why the wall-clock row is unresolved.
bench:ab output

bench-ab: 1642ef23 (merge base with origin/main) vs 355395d2

apps/mobile-benchmark: e2e run --workers 1 tests/controls.e2e.ts tests/login-form.e2e.ts --target ios-simulator --grep press|keyboard|refus|reopen|login form. 8 pairs in random order, resolved after 8 pairs. Threshold ±5% and 10 ms. darwin arm64, Apple M5 Pro x18, Node 26.13.1, load 10.8.

The suite's tests or config differ between base and head, so each side ran its own. A timing change can be the test change.

Behavior

These tests are left out of the timing rows below.

  • added tests/controls.e2e.ts › control inventory › device.keyboard types into the focused field and Backspace deletes (ios-simulator)

  • unstable on head (2 different step sequences) tests/controls.e2e.ts › control inventory › screenshot, restart, and clearState reopen the app on its home list (ios-simulator)

  • changed tests/controls.e2e.ts › refusals › keys the soft keyboard cannot send are refused by the engine (ios-simulator)

    + locator locator.press "getByTestId(\"Login Form\")" failed UNSUPPORTED_CAPABILITY
    
Timings

Every row but the process wall clock covers the 68 tests whose behavior matched.

Metricbase median (IQR)head median (IQR)change (95% CI)verdict
wall (process)132.42 s (127.02 s-139.82 s)139.38 s (136.13 s-146.35 s)+5.6% (-1.2% to +13.8%)unresolved
suite (sum of attempts)113.96 s (111.13 s-115.18 s)113.23 s (109.50 s-114.23 s)-0.3% (-2.0% to +4.0%)same
action (events)54.05 s (52.76 s-55.40 s)52.62 s (51.49 s-53.95 s)-1.7% (-7.0% to +3.4%)unresolved
step locator.fill23.28 s (22.70 s-23.35 s)23.11 s (22.91 s-23.31 s)-0.6% (-1.3% to +4.2%)same
step locator.tap19.05 s (18.42 s-19.54 s)18.59 s (17.97 s-18.77 s)-2.8% (-4.7% to +0.8%)same
step app.open16.56 s (15.40 s-17.93 s)15.65 s (14.78 s-16.06 s)-5.8% (-13.4% to +3.3%)unresolved
step expect.toBeVisible11.60 s (11.26 s-12.72 s)11.86 s (11.65 s-12.55 s)+0.7% (-12.7% to +19.5%)unresolved
step expect.toHaveText10.63 s (10.52 s-10.72 s)10.55 s (10.53 s-10.72 s)-0.2% (-2.3% to +1.7%)same
step locator.waitFor10.19 s (10.16 s-10.22 s)10.19 s (10.19 s-10.20 s)+0.0% (-0.6% to +0.8%)same, under the floor
step locator.press9.79 s (8.89 s-11.12 s)9.58 s (8.53 s-10.47 s)-3.8% (-23.8% to +19.4%)unresolved
step locator.longPress2.88 s (2.81 s-2.91 s)2.66 s (2.64 s-2.87 s)-4.9% (-8.6% to +0.3%)unresolved
step device.installApp1.56 s (1.14 s-1.93 s)1.15 s (1.10 s-1.58 s)-15.8% (-41.6% to +14.7%)unresolved
step expect.toContainText83 ms (60 ms-121 ms)60 ms (57 ms-91 ms)-22.0% (-52.3% to +53.2%)unresolved
step expect.toHaveValue71 ms (71 ms-77 ms)79 ms (71 ms-103 ms)+3.8% (-15.9% to +45.1%)same, under the floor
Counters
Counterbasehead
attempts1112-13
events engine3236
events poll2429-30
steps7386-88
tests flaky00-1
tests passed99-10
Tests outside the threshold: 0 of 68

With 68 tests compared at 95%, about 3.4 could land outside by chance.

The videos below show the new benchmark test on iOS, and then the Android emulator run against Settings search.

Checklist

  • Changeset added (pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only.
  • Breaking change: not breaking.
  • Docs updated in the same PR: the docs/**/*.mdx page for the behavior, and skills/e2e/ if the skill describes it.
  • Contract change: the mobile Device type is pinned in packages/mobile/tests/types/engine.ts; no wire change.
  • Engine contract change (e2e/engine): none. The change is limited to the mobile engine.

🤖 Generated with Claude Code

https://github.com/user-attachments/assets/d7a18a22-06f2-498b-bddd-5a92809cb288

https://github.com/user-attachments/assets/1ed9c687-205f-4892-a9de-4a1ae92deac3

Summary by CodeRabbit

  • New Features
    • Added device-level keyboard controls for typing into the focused field and pressing Enter, Space, Backspace, or a single character.
    • Pressing a key on an unfocused editable field focuses it first. Backspace works on enabled, editable text fields where supported.
  • Bug Fixes
    • Unsupported keys and fields that cannot accept text input return capability errors.
  • Documentation
    • Updated mobile keyboard guidance and provider limitations. Backspace is unsupported on Android devices from BrowserStack, TestMu AI, or Revyl, and on Revyl iOS. Focused-field typing is also unavailable on Revyl iOS. Use clear() or fill() as alternatives.