diff --git a/ScreensUITests/ScreensUITests.swift b/ScreensUITests/ScreensUITests.swift index 3186c20..9a543fd 100644 --- a/ScreensUITests/ScreensUITests.swift +++ b/ScreensUITests/ScreensUITests.swift @@ -117,9 +117,21 @@ final class ScreensUITests: XCTestCase { wait(for: [expectation(for: askedForKeyboard, evaluatedWith: diag)], timeout: 3) - // Type into the active first responder. Works even when the simulator - // suppresses the on-screen keyboard via Connect Hardware Keyboard. - app.typeText("hi") + // Force the on-screen keyboard to appear (simulator suppresses it + // when Connect Hardware Keyboard is on). + // The simulator can be told to disconnect the host keyboard via the + // hardware menu; we instead just wait briefly and then attempt taps. + Thread.sleep(forTimeInterval: 0.5) + + // If the system keyboard is visible, drive it like a user. Otherwise + // fall back to typeText (which bypasses the UI keyboard). + let kb = app.keyboards.firstMatch + if kb.waitForExistence(timeout: 1) { + kb.keys["h"].tap() + kb.keys["i"].tap() + } else { + app.typeText("hi") + } let typedH = NSPredicate(format: "label CONTAINS %@", "[ins:h]") wait(for: [expectation(for: typedH, evaluatedWith: diag)], timeout: 3)