feat(mobile): add device.isKeyboardShown()
What and why
-
Adds
device.isKeyboardShown(): Promise<boolean>to@e2e-dev/mobile, the AppiumisKeyboardShown()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 fact answer visible,derivedtrueabsentfalsevisibility-only,tree-rejectedwithvisiblethat visibletree-rejectedwithoutvisibletruefor a keyboard element drawn on screen. With none, the keyboard is moving: it is captured again briefly, thenENGINE_FAILURE(whichexpect.pollretries)unmeasurable, or no readingtruefor a keyboard element drawn on screen. With none:ENGINE_FAILUREfor a sparse or cut tree, elseUNSUPPORTED_CAPABILITY. Onlyabsent(or a hidden probe) answersfalse -
It is a recorded step (
device.isKeyboardShown), bounded byactionTimeout, 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 (keyboardShownIninpackages/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 thejaandzhpages 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-rejectedwithoutvisibleright afterfill, 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()) readfalse,true,falseon an earlier build. apps/mobile-benchmark/tests/device.e2e.tson the iOS 27.2 simulator, with the benchmark app built after #1898: the new keyboard test and both onboarding tests pass, twice.isKeyboardShownpolling read 4 settling captures beforetrue, and the phone step dismisses. That run also carried the separate iOS 27 toolbar fix fordismissKeyboard, 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/**/*.mdxpage for the behavior, andskills/e2e/if the skill describes it. - Contract change: emitted
.d.tsreviewed (packages/mobile/dist/device.d.ts).tests/types/sdk-types.tscoverse2e, not the mobileDeviceinterface, so it is unchanged; no wire change. - Engine contract change (
e2e/engine): changesets fore2e,@e2e-dev/web, and@e2e-dev/mobile.
🤖 Generated with Claude Code