pressEnter, hideKeyboard
Fires the keyboard's commit action, or closes the on-screen keyboard.
Functions
| function | description |
|---|---|
pressEnter(settle:) |
Fires the Enter / IME action (search, done, submit, newline …) on the currently focused input. When no field has focus, it waits up to 1.5 seconds for focus to land or the keyboard to appear, then sends Enter. If focus still has not landed, the step does not fail on iOS: Enter is sent anyway and the step gets a note saying no field had focus (the key may have gone to the field that had focus before). On Android, it fails without sending Enter when no field has input focus, or when the focused field's input connection is already closed (Flutter closes it after an Enter), because no one would receive the key; tap the field before pressing Enter again. |
hideKeyboard(settle:) |
Closes the on-screen keyboard. Does nothing when no keyboard is showing, so it is safe to call unconditionally. On Android it presses the back key. On iOS it taps an empty spot above the keyboard (a point that is on no element, or only on a screen-wide container you cannot operate; never on text, images, buttons or input fields, a toast, or the status bar; spots right next to a button or link are tried last so as not to press it), and if no empty spot exists (a web page that fills the screen) or tapping it does not close the keyboard, it taps the Done button of the keyboard's own toolbar (the system's Previous / Next / Done bar above the keyboard that web fields show; never an app's own toolbar). Only if the keyboard is still showing does it press Enter. The next action (such as tap) waits until the screen information no longer reports the keyboard before it looks for its element (Android; on some devices the keyboard stays reported for a few seconds after it closes, hiding elements at the bottom edge). |
Example
type("#search_box", "watch")
pressEnter() // fires the field's commit action
android {
hideKeyboard()
}
Notes
- Whether
pressEnter(settle:)inserts a newline or fires a commit action depends on the field, not on the command — see type for the same question about a trailing\nintype. - iOS
hideKeyboard(): which framework closes on a tap of the background differs. In our measurements on the iOS Simulator, a background tap closes the keyboard in Compose Multiplatform, while SwiftUI and Flutter close on the Enter that follows. If neither closes it, the step fails. React Native in the inapp-boost mode (the default) closes the keyboard before any background tap by releasing it from the focused input field (no Enter is sent, so nothing is submitted or searched). In the xcuitest mode this release does not exist (the XCUITest bridge refuses the request), so React Native follows the same order as the other frameworks: the background tap, then Enter. The step note names the tapped point. When the tap did not close the keyboard and Enter was sent, the note says that Enter also fires the field's return-key action (search, submit, next field). If elements above the keyboard disappeared after the tap, the note asks you to check that nothing was triggered. - A target under the keyboard: when
tap/type/clearInputfinds that the target's centre is under the keyboard, it first scrolls the container, and if the target is still covered, closes the keyboard by a means with no side effect (iOS: the background tap above, preceded by the release of the focused field in React Native's inapp-boost mode; Android: the back key) and acts. If the keyboard cannot be closed that way,tappresses the visible part of the target when its top edge shows above the keyboard;type/clearInput, and atapwith no visible part, fail the step without touching anything — the return key would close it but also fires the field's action, so it is never pressed automatically. CallpressEnter()before the step if that is what you want. If the previous step tapped the field,type/clearInputtreat it as the focused field and type without closing the keyboard. On Android, when the target is not found while the keyboard is showing (the window shrinks above the keyboard and elements below it leave the tree), the keyboard is closed with the back key and the target is looked up once more. MCPft_tap/ft_typedo not close the keyboard and refuse a target under it (on Android, and on Compose Multiplatform iOS whose window shrinks, the target leaves the tree); during exploration callft_hide_keyboardfirst. - Verifying whether the keyboard is showing is a separate assertion; see keyboard assertions.
settle: falseskips this command's post-action wait for the screen to settle (the next step may see a moving screen). See tap for details.