feat(mobile): add device.isKeyboardShown()

Merged
LE
4d ago
+612-69

What and why

  • Adds device.isKeyboardShown(): Promise<boolean> to @e2e-dev/mobile, the Appium isKeyboardShown() row from the umbrella issue.

  • It reads one capture (a sparse tree is captured again first) and answers from what agent-device reports for the keyboard, else from visible keyboard elements in the tree: the same band observations hide covered nodes under (keyboardBand, packages/mobile/src/nodes.ts).

    agent-device keyboard factanswer
    visible, derivedtrue
    absentfalse
    visibility-only, tree-rejected with visiblethat visible
    tree-rejected without visibletrue for a keyboard element drawn on screen. With none, the keyboard is moving: it is captured again briefly, then ENGINE_FAILURE (which expect.poll retries)
    unmeasurable, or no readingtrue for a keyboard element drawn on screen. With none: ENGINE_FAILURE for a sparse or cut tree, else UNSUPPORTED_CAPABILITY. Only absent (or a hidden probe) answers false
  • It is a recorded step (device.isKeyboardShown), bounded by actionTimeout, and changes nothing on the device. It reads the screen as it is now, so after an action that closes the keyboard the docs say to poll it:

    await screen.getByTestId('email-input').fill('jane@example.com');
    await device.dismissKeyboard();
    await expect.poll(() => device.isKeyboardShown()).toBe(false);
    
  • dismissKeyboard(), and the wait before acting on a control after the keyboard opened or closed, decide whether the keyboard is up by the same rule (keyboardShownIn in packages/mobile/src/keyboard.ts): a reading that cannot answer means no drag. The dismissing drag starts above the highest keyboard element drawn on screen, suggestion strip included (keyboardElementsTop), so a capture that lists only the strip (a hardware keyboard) drags from above it. A keyboard reported up with no frame and no keyboard element on screen gets no drag: UNSUPPORTED_CAPABILITY, since no point is known to be above it.

  • Docs: docs/reference/mobile.mdx (summary row, entry, Throws), the Appium guide row moves from "What e2e doesn't have yet" to "Map each command", and the ja and zh pages get the new heading and code so their outline still matches. The mobile README lists the method.

Issue

Part of #1855, checklist item device.isKeyboardShown() (Device and app).

Verified

Ran it locally: yes

  • iOS 27.2 simulator (iPhone 18 Pro), Xcode 27.2, the built CLI from this branch in a scratch project on Contacts: open a new contact, type a first name, close and discard it, so nothing is saved.
on the contact list: false
after typing a first name: true
after discarding the form: true
after discarding the form: true
after discarding the form: true
after discarding the form: true
after discarding the form: true
after discarding the form: false
   ✓ |ios| keyboard.e2e.ts > isKeyboardShown follows the soft keyboard on a new contact form 27.18s
      Tests  1 passed (1)

The true reads after the discard are real: the sheet and the keyboard animate out for about 2.5 s on that machine.

  • A second run passed the same way. On this simulator agent-device reports tree-rejected without visible right after fill, while the keyboard slides in. Such a reading is now captured again until the keyboard lands.
  • The same check in Safari (address bar, then dismissKeyboard()) read false, true, false on an earlier build.
  • apps/mobile-benchmark/tests/device.e2e.ts on the iOS 27.2 simulator, with the benchmark app built after #1898: the new keyboard test and both onboarding tests pass, twice. isKeyboardShown polling read 4 settling captures before true, and the phone step dismisses. That run also carried the separate iOS 27 toolbar fix for dismissKeyboard, which comes as its own PR; without it, iOS 27 refuses the first drag. Some runs failed earlier, reading the home list, while the Mac's load average was 30 to 200. Android was not run locally. The Android emulator in CI draws no soft keyboard, even for a tapped field, so the keyboard reads are their own iOS-only test (isKeyboardShown follows the keyboard up and through a dismissal), and the onboarding test is unchanged from main.

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 (packages/mobile/dist/device.d.ts). tests/types/sdk-types.ts covers e2e, not the mobile Device interface, so it is unchanged; no wire change.
  • Engine contract change (e2e/engine): changesets for e2e, @e2e-dev/web, and @e2e-dev/mobile.

🤖 Generated with Claude Code