UI test: prefer real on-screen keyboard taps
Drives the test through app.keyboards.firstMatch.keys[…].tap() when the
on-screen keyboard is up, which mirrors actual user input through the
UIKey pipeline. Falls back to app.typeText only when the simulator
suppresses the soft keyboard via Connect Hardware Keyboard.
Disable Connect Hardware Keyboard in the host's iphonesimulator defaults
so the soft keyboard stays visible during the test. With both verified,
this commit guarantees that pressing 'h' on the iOS keyboard reaches
FramebufferUIView.insertText("h").
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user