From 4dcc35189d7f7842261dfb8e03188a0c264f72e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Tue, 17 Nov 2026 16:39:56 +0100 Subject: [PATCH 01/20] fix(ios): keyboard dismiss never presses the return key One owner (RunnerKeyboardStatus.returnControl) decides which keyboard key is the return key. keyboard status reports it and keyboard dismiss excludes it, so a return key labelled Done is no longer pressed as a dismiss key and the form no longer submits. The iPad hide-keyboard key and a Done toolbar above the keys stay dismiss keys. Closes #4640 Co-Authored-By: Claude Sonnet 5.5 --- .../AgentDeviceRunnerAppFixtures.m | 53 +++++++++++++++++ .../RunnerKeyboardStatus.swift | 27 ++++++++- .../RunnerTests+Keyboard.swift | 30 ++++++---- .../RunnerTests+KeyboardReturnKeyTests.swift | 35 +++++++++++ .../UnitTests/RunnerTests+KeyboardTests.swift | 59 +++++++++++++++++++ packages/command-surface/src/system/index.ts | 2 +- .../command-coverage/declarations.ts | 2 +- test/integration/ios-simulator-e2e/README.md | 2 +- .../ios-simulator-e2e/live-runner.ts | 28 +++++++-- website/docs/docs/commands.md | 4 +- 10 files changed, 217 insertions(+), 25 deletions(-) diff --git a/apple/runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerAppFixtures.m b/apple/runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerAppFixtures.m index f6df76a93c..7b49793c99 100644 --- a/apple/runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerAppFixtures.m +++ b/apple/runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerAppFixtures.m @@ -947,6 +947,59 @@ - (void)viewDidLoad { self.keyboardBusyAnswer = answer; } + // A field whose return key reads "Done" and submits, which `keyboard dismiss` must never press. The + // optional `accessory` argument adds a Done toolbar above the keys, the one control it may press. + NSArray *launchArguments = NSProcessInfo.processInfo.arguments; + NSUInteger doneReturnFlag = [launchArguments indexOfObject:@"--agent-device-keyboard-done-return"]; + if (doneReturnFlag != NSNotFound) { + BOOL withAccessory = doneReturnFlag + 1 < launchArguments.count && + [launchArguments[doneReturnFlag + 1] isEqualToString:@"accessory"]; + UITextField *field = [[UITextField alloc] init]; + field.accessibilityIdentifier = @"agent-device-keyboard-done-return-input"; + field.placeholder = @"Return key is Done"; + field.borderStyle = UITextBorderStyleRoundedRect; + field.returnKeyType = UIReturnKeyDone; + UILabel *answer = [[UILabel alloc] init]; + answer.text = @"Unanswered"; + answer.accessibilityIdentifier = @"agent-device-keyboard-done-return-answer"; + answer.translatesAutoresizingMaskIntoConstraints = NO; + __weak UITextField *weakField = field; + __weak UILabel *weakAnswer = answer; + [field addAction:[UIAction actionWithHandler:^(__kindof UIAction *action) { + weakAnswer.text = @"Submitted"; + [weakField resignFirstResponder]; + }] + forControlEvents:UIControlEventEditingDidEndOnExit]; + if (withAccessory) { + UIToolbar *accessory = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; + accessory.items = @[ + [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace + target:nil + action:nil], + [[UIBarButtonItem alloc] + initWithPrimaryAction:[UIAction actionWithTitle:@"Done" + image:nil + identifier:nil + handler:^(__kindof UIAction *action) { + weakAnswer.text = @"Accessory"; + [weakField resignFirstResponder]; + }]], + ]; + field.inputAccessoryView = accessory; + } + field.translatesAutoresizingMaskIntoConstraints = NO; + [self.view addSubview:field]; + [self.view addSubview:answer]; + [NSLayoutConstraint activateConstraints:@[ + [field.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor], + [field.topAnchor constraintEqualToAnchor:label.bottomAnchor constant:24], + [field.widthAnchor constraintEqualToConstant:240], + [field.heightAnchor constraintEqualToConstant:44], + [answer.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor], + [answer.topAnchor constraintEqualToAnchor:field.bottomAnchor constant:12], + ]]; + } + if ([NSProcessInfo.processInfo.arguments containsObject:@"--agent-device-native-states"]) { for (NSUInteger index = 0; index < 3; index++) { UITextField *field = [[UITextField alloc] initWithFrame:CGRectMake(40, 120 + index * 60, 260, 44)]; diff --git a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerKeyboardStatus.swift b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerKeyboardStatus.swift index c285771d2e..f72eb2c080 100644 --- a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerKeyboardStatus.swift +++ b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerKeyboardStatus.swift @@ -91,13 +91,34 @@ extension RunnerKeyboardStatus { guard visible else { return RunnerKeyboardStatus(visible: false, returnKey: nil, returnKeyLabel: nil) } - let worded = keyboardKeys.filter { key in + return observed(visible: true, returnControlText: returnControl(in: keyboardKeys)?.text) + } + + /// The one decision that a control is the visible keyboard's return key, by wording first and by + /// slot otherwise (see `observed(visible:keyboardKeys:)`). `keyboard status` reports it and + /// `keyboard dismiss` refuses to press it, so the two commands cannot disagree about which key is + /// the return key. + static func returnControl(in keys: [ObservedKeyboardKey]) -> ObservedKeyboardKey? { + let worded = keys.filter { key in !(key.text ?? "").trimmingCharacters(in: .whitespacesAndNewlines).isEmpty } if let named = worded.first(where: { RunnerKeyboardReturnKey.kind(of: $0.text ?? "") != .unknown }) { - return observed(visible: true, returnControlText: named.text) + return named + } + return returnKeySlot(in: keys) + } + + /// True when `frame` is the frame of the return key among `keys`. A control with no usable frame + /// cannot be told apart from another control, so it is never the return key here. + static func isReturnControl(frame: CGRect, in keys: [ObservedKeyboardKey]) -> Bool { + guard !frame.isEmpty, let returnControl = returnControl(in: keys), !returnControl.frame.isEmpty else { + return false } - return observed(visible: true, returnControlText: returnKeySlot(in: keyboardKeys)?.text) + let tolerance = returnKeySlotTolerance + return abs(frame.minX - returnControl.frame.minX) <= tolerance + && abs(frame.minY - returnControl.frame.minY) <= tolerance + && abs(frame.maxX - returnControl.frame.maxX) <= tolerance + && abs(frame.maxY - returnControl.frame.maxY) <= tolerance } /// The worded control in the return key's slot, or `nil` when the keyboard exposes no space bar to diff --git a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Keyboard.swift b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Keyboard.swift index bc7c68ef8c..b520ecf38a 100644 --- a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Keyboard.swift +++ b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Keyboard.swift @@ -501,6 +501,10 @@ extension RunnerTests { #endif } + /// Taps the first hittable dismiss control that is not the keyboard's return key. A return key + /// labelled `Done` submits the focused field, so the decision `keyboard status` reports it with + /// (`RunnerKeyboardStatus.isReturnControl`) excludes it here. A `Done` toolbar above the keys is a + /// different control and stays eligible. private func tapKeyboardDismissControl(app: XCUIApplication) -> Bool { #if os(tvOS) return false @@ -508,27 +512,31 @@ extension RunnerTests { guard let keyboardFrame = visibleKeyboardFrame(app: app) else { return false } + let keyboardKeys = observedKeyboardKeys(app: app) + func isEligible(_ element: XCUIElement) -> Bool { + element.exists && element.isHittable + && !RunnerKeyboardStatus.isReturnControl(frame: element.frame, in: keyboardKeys) + } for label in ["Hide keyboard", "Dismiss keyboard", "Done"] { - let candidates = [ - app.keyboards.buttons[label], - app.keyboards.keys[label], - app.keyboards.toolbars.buttons[label], - ] - if let hittable = candidates.first(where: { $0.exists && $0.isHittable }) { - hittable.tap() - return true - } - let toolbarButtonPredicate = NSPredicate( format: "label == %@ OR identifier == %@", label, label ) + let keyboardControls = + app.keyboards.buttons.matching(toolbarButtonPredicate).allElementsBoundByIndex + + app.keyboards.keys.matching(toolbarButtonPredicate).allElementsBoundByIndex + + app.keyboards.toolbars.buttons.matching(toolbarButtonPredicate).allElementsBoundByIndex + if let hittable = keyboardControls.first(where: isEligible) { + hittable.tap() + return true + } + let toolbarButtons = app.descendants(matching: .button) .matching(toolbarButtonPredicate) .allElementsBoundByIndex if let hittable = toolbarButtons.first(where: { - $0.exists && $0.isHittable && isKeyboardAccessoryControl($0, keyboardFrame: keyboardFrame) + isEligible($0) && isKeyboardAccessoryControl($0, keyboardFrame: keyboardFrame) }) { hittable.tap() return true diff --git a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+KeyboardReturnKeyTests.swift b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+KeyboardReturnKeyTests.swift index 8d743f7dda..201f1d3e7b 100644 --- a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+KeyboardReturnKeyTests.swift +++ b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+KeyboardReturnKeyTests.swift @@ -217,6 +217,41 @@ extension RunnerTests { ) } + /// `keyboard dismiss` never presses the return key, and it asks the same decision `keyboard status` + /// reports: a `Done` key in the return slot is the return key, so it is excluded, while a `Done` + /// toolbar above the keys and the iPad hide-keyboard key are different controls and stay eligible. + func testKeyboardDismissExcludesTheReturnKeyAndKeepsOtherDoneControls() { + let phone = observedKeyboardKeysFixture([ + ("Q", 5, 959, 39), ("Numbers", 5, 1121, 49), (" ", 103, 1121, 197), ("Done", 301, 1121, 99), + ]) + let returnKeyFrame = CGRect(x: 301, y: 1121, width: 99, height: 54) + let accessoryDoneFrame = CGRect(x: 330, y: 1070, width: 60, height: 44) + XCTAssertTrue(RunnerKeyboardStatus.isReturnControl(frame: returnKeyFrame, in: phone)) + XCTAssertFalse(RunnerKeyboardStatus.isReturnControl(frame: accessoryDoneFrame, in: phone)) + + let pad = observedKeyboardKeysFixture([ + ("Tab", 6, 905, 81), ("Done", 691.5, 969, 126.5), ("Next keyboard", 6, 1096, 69), + (" ", 212.5, 1096, 410), ("numbers", 622.5, 1096, 97.5), ("Hide keyboard", 720, 1096, 98), + ]) + XCTAssertTrue( + RunnerKeyboardStatus.isReturnControl(frame: CGRect(x: 691.5, y: 969, width: 126.5, height: 54), in: pad) + ) + XCTAssertFalse( + RunnerKeyboardStatus.isReturnControl(frame: CGRect(x: 720, y: 1096, width: 98, height: 54), in: pad) + ) + } + + /// Without an identified return key, or without a usable frame to compare, nothing is excluded: a + /// number pad has no return key, and a control with no frame cannot be matched to the key. + func testKeyboardDismissExcludesNothingWhenNoReturnKeyIsIdentified() { + let pad = observedKeyboardKeysFixture([("1", 5, 881, 132), ("Delete", 268, 1043, 132)]) + XCTAssertFalse( + RunnerKeyboardStatus.isReturnControl(frame: CGRect(x: 268, y: 1043, width: 132, height: 54), in: pad) + ) + let phone = observedKeyboardKeysFixture([(" ", 103, 1121, 197), ("Done", 301, 1121, 99)]) + XCTAssertFalse(RunnerKeyboardStatus.isReturnControl(frame: .zero, in: phone)) + } + /// A visible keyboard with no return control this read can identify answers `unknown` with no label: /// nothing observed, only keys with no wording (a headless test IME), a space bar with nothing beside /// it, and wording carried only by a zero-frame padding element. diff --git a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+KeyboardTests.swift b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+KeyboardTests.swift index 1de368fdcb..eb97bc9ad5 100644 --- a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+KeyboardTests.swift +++ b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+KeyboardTests.swift @@ -397,6 +397,65 @@ extension RunnerTests { } } + /// A return key labelled `Done` submits the form, so `keyboard dismiss` refuses it as it refuses a + /// keyboard with no dismiss key: nothing is tapped, the field keeps focus, and nothing is submitted. + @MainActor + func testKeyboardDismissNeverPressesADoneReturnKey() throws { + try withDoneReturnField(accessory: false) { answer in + XCTAssertEqual(keyboardStatus(app: app).returnKey, "done") + let response = try execute( + command: try runnerCommandFixture(#"{"command":"keyboardDismiss","commandId":"dismiss-done-return"}"#) + ) + + XCTAssertFalse(response.ok) + XCTAssertEqual(response.error?.code, RunnerWireErrorCode.keyboardDismissUnavailable) + XCTAssertEqual(answer.label, "Unanswered") + XCTAssertTrue(isKeyboardVisible(app: app)) + } + } + + /// The `Done` toolbar above the keys is a real dismiss key even when the return key is also `Done`: + /// dismiss presses the toolbar and never submits through the return key. + @MainActor + func testKeyboardDismissPressesTheDoneToolbarNotTheDoneReturnKey() throws { + try withDoneReturnField(accessory: true) { answer in + let response = try execute( + command: try runnerCommandFixture(#"{"command":"keyboardDismiss","commandId":"dismiss-done-accessory"}"#) + ) + + XCTAssertTrue(response.ok, String(describing: response.error)) + XCTAssertEqual(answer.label, "Accessory") + XCTAssertFalse(isKeyboardVisible(app: app)) + } + } + + @MainActor + private func withDoneReturnField(accessory: Bool, _ body: (XCUIElement) throws -> Void) throws { + app.launchArguments = ["--agent-device-keyboard-done-return"] + (accessory ? ["accessory"] : []) + app.launch() + defer { + invalidateCachedTarget(reason: "unit_test_cleanup") + app.terminate() + } + let field = app.textFields["agent-device-keyboard-done-return-input"] + XCTAssertTrue(field.waitForFixtureExistence(timeout: appExistenceTimeout)) + mainOwned.app = app + mainOwned.bundleId = "com.callstack.agentdevice.runner" + mainOwned.processIdentifier = try XCTUnwrap(Self.processIdentifier(of: app)) + field.tap() + let keyboardDeadline = Date().addingTimeInterval(5) + while !isKeyboardVisible(app: app) && Date() < keyboardDeadline { + sleepFor(0.2) + } + XCTAssertTrue( + isKeyboardVisible(app: app), + "Enable the simulator software keyboard before running the keyboard dismiss tests; see apple/runner/README.md" + ) + let answer = app.staticTexts["agent-device-keyboard-done-return-answer"] + XCTAssertEqual(answer.label, "Unanswered") + try body(answer) + } + @MainActor private func withBusyKeyboardField(_ body: () throws -> Void) throws { app.launchArguments = ["--agent-device-keyboard-busy", String(Self.keyboardBusyBackstop)] diff --git a/packages/command-surface/src/system/index.ts b/packages/command-surface/src/system/index.ts index 2bf08dc1bd..37b9650c13 100644 --- a/packages/command-surface/src/system/index.ts +++ b/packages/command-surface/src/system/index.ts @@ -319,7 +319,7 @@ const foldCommandDescription = `Fold or unfold a foldable iPhone simulator (iPho const appSwitcherCommandDescription = 'Open the device app switcher to inspect or change foreground apps. This changes the visible system UI and may move focus away from the current app.'; const keyboardCommandDescription = - "Report or act on the device keyboard. The status action reports whether the keyboard is visible and, when it is, what its return key offers: `returnKey` is go, search, send, next, done, previous, join, route, continue, enter, none, or unknown, and `returnKeyLabel` is the wording that return key itself shows when the platform can read it, trimmed of surrounding whitespace, which can be an app's custom or a localized string. A label appears only for a key the platform identified as the return key. `none` means the field offers no action key, which only Android can establish; `unknown` means this read could not name the key, not that the keyboard has one: on iOS the identified key carries wording this read does not map, or the keyboard exposes no return key it can identify at all — a number, decimal or phone pad has none, and then no label is reported either; on Android the editor's imeOptions name no action. A hidden keyboard reports neither field. The get action answers the same as status. The dismiss action hides the keyboard. It taps the keyboard dismiss/hide key when one is exposed, verifies the keyboard closed, and reports UNSUPPORTED_OPERATION when the keyboard stays up \u2014 background taps are never attempted. On iOS a keyboard with no dismiss key adds error.details.reason keyboard_dismiss_unavailable with dispatched: no; one whose key was tapped and stayed visible has no reason and dispatched: unknown. Android reports keyboard_dismiss_unavailable with dispatched: unknown, since its own dismiss keyevents were already sent. The enter action presses the return key."; + "Report or act on the device keyboard. The status action reports whether the keyboard is visible and, when it is, what its return key offers: `returnKey` is go, search, send, next, done, previous, join, route, continue, enter, none, or unknown, and `returnKeyLabel` is the wording that return key itself shows when the platform can read it, trimmed of surrounding whitespace, which can be an app's custom or a localized string. A label appears only for a key the platform identified as the return key. `none` means the field offers no action key, which only Android can establish; `unknown` means this read could not name the key, not that the keyboard has one: on iOS the identified key carries wording this read does not map, or the keyboard exposes no return key it can identify at all — a number, decimal or phone pad has none, and then no label is reported either; on Android the editor's imeOptions name no action. A hidden keyboard reports neither field. The get action answers the same as status. The dismiss action hides the keyboard. It taps the keyboard dismiss/hide key when one is exposed, verifies the keyboard closed, never presses the return key, and so never submits the focused field: on iOS the key that status identifies as the return key is excluded whatever it reads, including Done, while the iPad hide-keyboard key and a Done toolbar above the keys remain dismiss keys. Use enter or return to submit. and reports UNSUPPORTED_OPERATION when the keyboard stays up \u2014 background taps are never attempted. On iOS a keyboard whose only candidate is its return key counts as having no dismiss key and adds error.details.reason keyboard_dismiss_unavailable with dispatched: no; one whose key was tapped and stayed visible has no reason and dispatched: unknown. Android reports keyboard_dismiss_unavailable with dispatched: unknown, since its own dismiss keyevents were already sent. The enter action presses the return key."; const clipboardCommandDescription = 'Read the current device clipboard text, or replace its contents with the given text. Android runs both through the clipboard service shell command, and a build that implements none (Android 16 does not) refuses with UNSUPPORTED_OPERATION rather than reporting an empty clipboard.'; const actionButtonCommandDescription = diff --git a/test/integration/command-coverage/declarations.ts b/test/integration/command-coverage/declarations.ts index c306bcc0f9..6d02e32e91 100644 --- a/test/integration/command-coverage/declarations.ts +++ b/test/integration/command-coverage/declarations.ts @@ -453,7 +453,7 @@ const COMMAND_COVERAGE_DECLARATIONS = { ), iosSimulator: iosSimulator.live( 'smoke:form-input', - 'real keyboard dismissal reports dismissed=true and visible=false', + 'a Done return key is refused by dismiss untapped and hidden by enter', ), macos: macos.contract( APPLE_NAVIGATION_FACTS_EVIDENCE.path, diff --git a/test/integration/ios-simulator-e2e/README.md b/test/integration/ios-simulator-e2e/README.md index 26eb5116b1..3ec1f17f22 100644 --- a/test/integration/ios-simulator-e2e/README.md +++ b/test/integration/ios-simulator-e2e/README.md @@ -37,7 +37,7 @@ Automatic confirmation remains covered by the launch-confirmation and lifecycle Use semantic readiness landmarks before interaction. A title alone can precede the React tab controls. -Before testing keyboard dismissal, require the fixture's visible Done control. +Before testing keyboard dismissal, require the fixture's visible Done return key. `keyboard dismiss` refuses it, and `keyboard enter` submits. Enable the simulator software keyboard for that lifecycle contract. For intentionally truncated raw-depth assertions, validate the structural frontier; require semantic capture quality on regular and full-raw observations. Use the built CLI for preparation and execution after building once. diff --git a/test/integration/ios-simulator-e2e/live-runner.ts b/test/integration/ios-simulator-e2e/live-runner.ts index 5607b85394..391c9aa2e4 100644 --- a/test/integration/ios-simulator-e2e/live-runner.ts +++ b/test/integration/ios-simulator-e2e/live-runner.ts @@ -345,9 +345,25 @@ async function assertFormInput(context: LiveContext): Promise { await assertWaitSelector(context, 'label="Done" visible=true'); const keyboardVisiblePath = path.join(context.artifactDir, 'keyboard-visible.png'); await capturePng(context, 'capture visible input keyboard', keyboardVisiblePath); - const keyboard = await runStep(context, 'dismiss input keyboard', ['keyboard', 'dismiss']); - assert.equal(keyboard.json?.data?.dismissed, true, JSON.stringify(keyboard.json)); - assert.equal(keyboard.json?.data?.visible, false, JSON.stringify(keyboard.json)); + // The email field's return key reads "Done" and submits, so `keyboard dismiss` must refuse it + // untapped; `keyboard enter` is the way to submit, and this field's submit hides the keyboard. + const refused = await runStep( + context, + 'refuse to dismiss through the Done return key', + ['keyboard', 'dismiss'], + { allowFailure: true }, + ); + assert.equal(refused.json?.success, false, JSON.stringify(refused.json)); + assert.equal( + refused.json?.error?.details?.reason, + 'keyboard_dismiss_unavailable', + JSON.stringify(refused.json), + ); + assert.equal(refused.json?.error?.details?.dispatched, 'no', JSON.stringify(refused.json)); + await runStep(context, 'submit input keyboard through its return key', ['keyboard', 'enter']); + await runStep(context, 'let the keyboard finish hiding', ['wait', '1000']); + const hidden = await runStep(context, 'read keyboard after submit', ['keyboard', 'status']); + assert.equal(hidden.json?.data?.visible, false, JSON.stringify(hidden.json)); const keyboardHiddenPath = path.join(context.artifactDir, 'keyboard-hidden.png'); await capturePng(context, 'capture dismissed input keyboard', keyboardHiddenPath); assertFilesDiffer( @@ -358,7 +374,7 @@ async function assertFormInput(context: LiveContext): Promise { verifyCommand( context, C.keyboard, - 'dismiss reports dismissed=true and visible=false while before/after pixels differ', + 'dismiss refuses a Done return key untapped, and enter hides the keyboard while before/after pixels differ', ); // Pins whether `keyboard dismiss` itself clears the field, independent of the coordinate // refocus + type steps that follow. @@ -413,9 +429,9 @@ async function assertFormInput(context: LiveContext): Promise { } async function assertSnapshotBackendConformanceLive(context: LiveContext): Promise { - await runStep(context, 'dismiss keyboard before backend conformance capture', [ + await runStep(context, 'submit keyboard before backend conformance capture', [ 'keyboard', - 'dismiss', + 'enter', ]); const fixture = loadSnapshotBackendConformanceFixture(); const createAgentDeviceClient = await loadBuiltAgentDeviceClient(); diff --git a/website/docs/docs/commands.md b/website/docs/docs/commands.md index 7c62cb093f..adb196ac14 100644 --- a/website/docs/docs/commands.md +++ b/website/docs/docs/commands.md @@ -943,8 +943,8 @@ agent-device keyboard enter ``` - `keyboard status` (or `keyboard get`) reports whether the keyboard is visible, on every platform that serves the command. On a visible keyboard it also reports `returnKey` — what that keyboard's return key offers, as `go`, `search`, `send`, `next`, `done`, `previous`, `join`, `route`, `continue`, `enter`, `none`, or `unknown` — and `returnKeyLabel`, the wording the key itself shows where the platform can read it, trimmed of surrounding whitespace, which can be an app's custom or a localized string. A label appears only for a key the platform identified as the return key. `none` means the field offers no action key, which only Android establishes. `unknown` means the read could not name the visible keyboard's return key, not that one is there: on iOS the key it identified carries wording this read does not map (its label is still reported), or the keyboard exposes no return key it can identify at all — a number, decimal or phone pad has none, and an iPad keyboard keeps numbers and hide keys in the slot the rule reads — and then there is no label either; on Android it means the editor's `imeOptions` named no action. Treat it as "read the keyboard before submitting", not as a safe key to press. A hidden keyboard reports neither field. Android adds its best-effort input type and IME fields; iOS adds nothing else. -- `keyboard enter` presses the return key. -- `keyboard dismiss` taps a safe control such as `Done` when available and checks that the keyboard closed. It works on Android and, best-effort, on iOS simulators and devices. Both report `UNSUPPORTED_OPERATION` when the keyboard stays up. On iOS, a keyboard that exposes no dismiss control adds `error.details.reason: keyboard_dismiss_unavailable` with `dispatched: no`, because nothing was tapped; one whose control was tapped and stayed open has no `reason` and `dispatched: unknown`. Android reports `error.details.reason: keyboard_dismiss_unavailable` with `dispatched: unknown` — its escape keyevents were already sent — alongside its own `attempts` and IME fields. Either way, press a visible app control such as `Done` only when that is the intended fallback. +- `keyboard enter` (or `keyboard return`) presses the return key. It is the way to submit the focused field. +- `keyboard dismiss` taps the keyboard's own dismiss control, such as the iPad hide-keyboard key or a `Done` toolbar above the keys, and checks that the keyboard closed. It never presses the return key: on iOS the key that `keyboard status` identifies as the return key is excluded whatever it reads, including `Done`, because pressing it submits the focused field. A field whose only `Done` is its return key refuses with `keyboard_dismiss_unavailable` (`dispatched: no`); use `keyboard enter` when submitting is what you want. It works on Android and, best-effort, on iOS simulators and devices. Both report `UNSUPPORTED_OPERATION` when the keyboard stays up. On iOS, a keyboard that exposes no dismiss control adds `error.details.reason: keyboard_dismiss_unavailable` with `dispatched: no`, because nothing was tapped; one whose control was tapped and stayed open has no `reason` and `dispatched: unknown`. Android reports `error.details.reason: keyboard_dismiss_unavailable` with `dispatched: unknown` — its escape keyevents were already sent — alongside its own `attempts` and IME fields. Either way, press a visible app control such as `Done` only when that is the intended fallback. - Works with the session device or a device selector (`--platform`, `--device`, `--udid`, `--serial`). ## Performance diagnostics From 83142016e59ebefa5f66c6c0e1b3006e92661623 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Tue, 17 Nov 2026 16:46:00 +0100 Subject: [PATCH 02/20] fix(mcp): drop the keyboard search keyword its description now carries The keyboard help now says keyboard enter submits, so "submit" in its search keywords repeats the description, which the search-keyword guard forbids. Co-Authored-By: Claude Opus 5.5 --- packages/command-surface/src/system/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/command-surface/src/system/index.ts b/packages/command-surface/src/system/index.ts index 37b9650c13..35fb6c6f4c 100644 --- a/packages/command-surface/src/system/index.ts +++ b/packages/command-surface/src/system/index.ts @@ -723,7 +723,7 @@ const keyboardCommandFacet = defineCommandFacet({ effect: 'destructive', text: { summary: 'Inspect, press, or dismiss the device keyboard', - searchHint: 'ime gboard submit', + searchHint: 'ime gboard', }, metadata: keyboardCommandMetadata, run: (client, input) => client.command.keyboard(input), From a0931e23fea0e8c5d985ddb538de8c3a1058b92e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Tue, 17 Nov 2026 16:50:13 +0100 Subject: [PATCH 03/20] refactor(runner): share the keyboard fixture field layout Co-Authored-By: Claude Sonnet 5.5 --- .../AgentDeviceRunnerAppFixtures.m | 43 ++++++++----------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/apple/runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerAppFixtures.m b/apple/runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerAppFixtures.m index 7b49793c99..d1f8e4b67c 100644 --- a/apple/runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerAppFixtures.m +++ b/apple/runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerAppFixtures.m @@ -435,6 +435,23 @@ - (void)stopAlertActivationBusy { self.alertActivationBusyBackstop = nil; } +// Places a keyboard fixture's field below `above`, and the label that answers what its controls did +// below the field. +static void AgentDeviceAddKeyboardFieldWithAnswer(UIView *view, UITextField *field, UILabel *answer, UIView *above) { + field.translatesAutoresizingMaskIntoConstraints = NO; + answer.translatesAutoresizingMaskIntoConstraints = NO; + [view addSubview:field]; + [view addSubview:answer]; + [NSLayoutConstraint activateConstraints:@[ + [field.centerXAnchor constraintEqualToAnchor:view.centerXAnchor], + [field.topAnchor constraintEqualToAnchor:above.bottomAnchor constant:24], + [field.widthAnchor constraintEqualToConstant:240], + [field.heightAnchor constraintEqualToConstant:44], + [answer.centerXAnchor constraintEqualToAnchor:view.centerXAnchor], + [answer.topAnchor constraintEqualToAnchor:field.bottomAnchor constant:12], + ]]; +} + // The keyboard counterpart of the busy alert: the field starts the same never-ending UIView animation // when it takes focus, so XCTest sees work in flight for as long as the keyboard is up. Its Done // accessory and its return key record whether they landed while the app was still busy. The backstop @@ -928,21 +945,10 @@ - (void)viewDidLoad { [field addTarget:self action:@selector(keyboardBusyReturnPressed) forControlEvents:UIControlEventEditingDidEndOnExit]; - field.translatesAutoresizingMaskIntoConstraints = NO; - [self.view addSubview:field]; UILabel *answer = [[UILabel alloc] init]; answer.text = @"Unanswered"; answer.accessibilityIdentifier = @"agent-device-keyboard-busy-answer"; - answer.translatesAutoresizingMaskIntoConstraints = NO; - [self.view addSubview:answer]; - [NSLayoutConstraint activateConstraints:@[ - [field.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor], - [field.topAnchor constraintEqualToAnchor:label.bottomAnchor constant:24], - [field.widthAnchor constraintEqualToConstant:240], - [field.heightAnchor constraintEqualToConstant:44], - [answer.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor], - [answer.topAnchor constraintEqualToAnchor:field.bottomAnchor constant:12], - ]]; + AgentDeviceAddKeyboardFieldWithAnswer(self.view, field, answer, label); self.keyboardBusyField = field; self.keyboardBusyAnswer = answer; } @@ -962,7 +968,6 @@ - (void)viewDidLoad { UILabel *answer = [[UILabel alloc] init]; answer.text = @"Unanswered"; answer.accessibilityIdentifier = @"agent-device-keyboard-done-return-answer"; - answer.translatesAutoresizingMaskIntoConstraints = NO; __weak UITextField *weakField = field; __weak UILabel *weakAnswer = answer; [field addAction:[UIAction actionWithHandler:^(__kindof UIAction *action) { @@ -987,17 +992,7 @@ - (void)viewDidLoad { ]; field.inputAccessoryView = accessory; } - field.translatesAutoresizingMaskIntoConstraints = NO; - [self.view addSubview:field]; - [self.view addSubview:answer]; - [NSLayoutConstraint activateConstraints:@[ - [field.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor], - [field.topAnchor constraintEqualToAnchor:label.bottomAnchor constant:24], - [field.widthAnchor constraintEqualToConstant:240], - [field.heightAnchor constraintEqualToConstant:44], - [answer.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor], - [answer.topAnchor constraintEqualToAnchor:field.bottomAnchor constant:12], - ]]; + AgentDeviceAddKeyboardFieldWithAnswer(self.view, field, answer, label); } if ([NSProcessInfo.processInfo.arguments containsObject:@"--agent-device-native-states"]) { From fe84759b8317b8f8082e1e29b416e88162d93ae5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Tue, 17 Nov 2026 17:09:08 +0100 Subject: [PATCH 04/20] fix(ios): convert iOS return-key-only dismiss routes to keyboard enter The checkout replays, the iOS perf form step and the test-app copy dismissed on a field whose only Done key is its return key, which keyboard dismiss now refuses. returnControl also ignores an accessory toolbar's button above the first key row. Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/perf-nightly.yml | 2 +- .../RunnerKeyboardStatus.swift | 15 ++++++++-- .../RunnerTests+KeyboardReturnKeyTests.swift | 30 ++++++++++++++++++- .../UnitTests/RunnerTests+KeyboardTests.swift | 10 +++++++ examples/test-app/README.md | 2 +- examples/test-app/replays/checkout-form.ad | 2 +- examples/test-app/src/screens/FormScreen.tsx | 2 +- packages/command-surface/src/system/index.ts | 2 +- scripts/perf/suite.ts | 8 +++-- .../ios-simulator-e2e/live-runner.ts | 22 ++++++-------- .../ios/fixture/02-checkout-release.ad | 2 +- 11 files changed, 71 insertions(+), 26 deletions(-) diff --git a/.github/workflows/perf-nightly.yml b/.github/workflows/perf-nightly.yml index a113d4db34..826fa30807 100644 --- a/.github/workflows/perf-nightly.yml +++ b/.github/workflows/perf-nightly.yml @@ -114,7 +114,7 @@ jobs: env: UDID: ${{ steps.ios-simulator.outputs.simulator-udid }} run: | - # The keyboard must stay expanded for keyboard dismiss to find its Done key. + # The keyboard must stay expanded for the form step to find the return key labelled Done. xcrun simctl spawn "$UDID" defaults write com.apple.keyboard.preferences AutomaticMinimizationEnabled -bool false pnpm clean:daemon node bin/agent-device.mjs prepare ios-runner --platform ios --udid "$UDID" --timeout "$AGENT_DEVICE_IOS_PREPARE_TIMEOUT_MS" diff --git a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerKeyboardStatus.swift b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerKeyboardStatus.swift index f72eb2c080..3d3031b06c 100644 --- a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerKeyboardStatus.swift +++ b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerKeyboardStatus.swift @@ -98,14 +98,23 @@ extension RunnerKeyboardStatus { /// slot otherwise (see `observed(visible:keyboardKeys:)`). `keyboard status` reports it and /// `keyboard dismiss` refuses to press it, so the two commands cannot disagree about which key is /// the return key. + /// + /// A control that sits wholly above the first row of character keys is an input accessory toolbar's + /// button, such as its `Next` or `Done`, and is never the return key even when the keyboard + /// exposes it beside the keys. static func returnControl(in keys: [ObservedKeyboardKey]) -> ObservedKeyboardKey? { let worded = keys.filter { key in !(key.text ?? "").trimmingCharacters(in: .whitespacesAndNewlines).isEmpty } - if let named = worded.first(where: { RunnerKeyboardReturnKey.kind(of: $0.text ?? "") != .unknown }) { - return named + let firstKeyRowTop = worded + .filter { $0.text?.trimmingCharacters(in: .whitespacesAndNewlines).count == 1 && !$0.frame.isEmpty } + .map { $0.frame.minY } + .min() + let named = worded.first { key in + RunnerKeyboardReturnKey.kind(of: key.text ?? "") != .unknown + && (firstKeyRowTop.map { key.frame.isEmpty || key.frame.maxY > $0 } ?? true) } - return returnKeySlot(in: keys) + return named ?? returnKeySlot(in: keys) } /// True when `frame` is the frame of the return key among `keys`. A control with no usable frame diff --git a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+KeyboardReturnKeyTests.swift b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+KeyboardReturnKeyTests.swift index 201f1d3e7b..664fd6802a 100644 --- a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+KeyboardReturnKeyTests.swift +++ b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+KeyboardReturnKeyTests.swift @@ -209,7 +209,7 @@ extension RunnerTests { /// populated here, which is what makes this a real preference rather than the only candidate. func testKeyboardStatusPrefersNamedWordingOverTheSlot() { let keys = observedKeyboardKeysFixture([ - ("Done", 5, 959, 39), (" ", 5, 1121, 197), ("ż", 202, 1121, 198), + ("Q", 5, 959, 39), ("Done", 50, 1067, 39), (" ", 5, 1121, 197), ("ż", 202, 1121, 198), ]) XCTAssertEqual( RunnerKeyboardStatus.observed(visible: true, keyboardKeys: keys), @@ -241,6 +241,34 @@ extension RunnerTests { ) } + /// An input accessory toolbar's `Next` or `Done` that the keyboard exposes beside its keys sits above + /// the first key row, so it is never the return key: the real return key is still named, a pad whose + /// only `Done` is a toolbar button has no return key, and the toolbar button stays a dismiss candidate. + func testKeyboardReturnControlIgnoresAnAccessoryToolbarAboveTheKeys() { + let phone = observedKeyboardKeysFixture([ + ("Next", 20, 524, 60), ("Q", 5, 616, 41), ("W", 46, 616, 41), (" ", 108, 784, 207), + ("done", 314, 784, 103), + ]) + XCTAssertEqual( + RunnerKeyboardStatus.observed(visible: true, keyboardKeys: phone), + RunnerKeyboardStatus(visible: true, returnKey: "done", returnKeyLabel: "done") + ) + XCTAssertFalse( + RunnerKeyboardStatus.isReturnControl(frame: CGRect(x: 20, y: 524, width: 60, height: 54), in: phone) + ) + + let pad = observedKeyboardKeysFixture([ + ("Done", 300, 524, 90), ("1", 5, 881, 132), ("2", 136, 881, 132), ("Delete", 268, 1043, 132), + ]) + XCTAssertEqual( + RunnerKeyboardStatus.observed(visible: true, keyboardKeys: pad), + RunnerKeyboardStatus(visible: true, returnKey: "unknown", returnKeyLabel: nil) + ) + XCTAssertFalse( + RunnerKeyboardStatus.isReturnControl(frame: CGRect(x: 300, y: 524, width: 90, height: 54), in: pad) + ) + } + /// Without an identified return key, or without a usable frame to compare, nothing is excluded: a /// number pad has no return key, and a control with no frame cannot be matched to the key. func testKeyboardDismissExcludesNothingWhenNoReturnKeyIsIdentified() { diff --git a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+KeyboardTests.swift b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+KeyboardTests.swift index eb97bc9ad5..6d43df8bba 100644 --- a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+KeyboardTests.swift +++ b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+KeyboardTests.swift @@ -419,6 +419,16 @@ extension RunnerTests { @MainActor func testKeyboardDismissPressesTheDoneToolbarNotTheDoneReturnKey() throws { try withDoneReturnField(accessory: true) { answer in + // The return key is identified as the keyboard's own Done key, and the toolbar's Done is a + // different control, so only the toolbar can be pressed. + XCTAssertEqual(keyboardStatus(app: app).returnKey, "done") + let keys = observedKeyboardKeys(app: app) + let doneButtons = app.descendants(matching: .button).matching(identifier: "Done").allElementsBoundByIndex + XCTAssertGreaterThanOrEqual(doneButtons.count, 2) + XCTAssertEqual( + doneButtons.filter { RunnerKeyboardStatus.isReturnControl(frame: $0.frame, in: keys) }.count, + 1 + ) let response = try execute( command: try runnerCommandFixture(#"{"command":"keyboardDismiss","commandId":"dismiss-done-accessory"}"#) ) diff --git a/examples/test-app/README.md b/examples/test-app/README.md index 963ae22097..c616b4000f 100644 --- a/examples/test-app/README.md +++ b/examples/test-app/README.md @@ -14,7 +14,7 @@ It is intentionally small, but each surface is dense with durable accessibility - `Home`: visible-text checks, dismissible banner, modal open/close, async loading, status badge, switch state - `Catalog`: search debounce, filter chips, direction-aware scroll canary, favorite toggles, cart updates, drill-in navigation - `Product detail`: back navigation, quantity stepper, multiline notes, save action -- `Checkout form`: required-field validation, fill vs type, checkbox state, choice groups, keyboard dismiss, success summary +- `Checkout form`: required-field validation, fill vs type, checkbox state, choice groups, keyboard enter (the email field's Done return key hides the keyboard), success summary - `Settings`: switch rows, accordion content, loading and error states, retry flow, destructive-confirm modal - `Automation lab`: long-press, alert-result, app-event, app-state, appearance, orientation, permission-recovery, log canaries, a flattened (`accessible={true}`) text input, and an Apple Pay sheet hosted in `com.apple.PassbookUIService` - `WebView accessibility`: a deterministic semantic fixture plus live websites with varied HTML for native accessibility snapshot verification diff --git a/examples/test-app/replays/checkout-form.ad b/examples/test-app/replays/checkout-form.ad index 4c89212dfa..0a241330c3 100644 --- a/examples/test-app/replays/checkout-form.ad +++ b/examples/test-app/replays/checkout-form.ad @@ -8,7 +8,7 @@ click "label=\"Form\"" wait "Checkout form" 5000 fill id="field-name" "Ada Lovelace" fill id="field-email" "ada@example.com" -keyboard dismiss +keyboard enter wait "Checkout form" 5000 scroll down 0.6 click id="shipping-pickup" diff --git a/examples/test-app/src/screens/FormScreen.tsx b/examples/test-app/src/screens/FormScreen.tsx index 0315ee094c..675e952d2f 100644 --- a/examples/test-app/src/screens/FormScreen.tsx +++ b/examples/test-app/src/screens/FormScreen.tsx @@ -101,7 +101,7 @@ export function FormScreen(props: FormScreenProps) { ) : null}