Xcode 7 UI Tests fail with "Timed out waiting for key event to complete"
Asked Answered
V

4

10

My team and I have been setting up a Jenkins server to automate running unit and ui tests on a Mac Mini that we use as a build server. This Mac Mini has no peripherals attached to it, and the only way we can access it is by logging in remotely.

When I am logged into the machine remotely, using my Mac's built in Screen Sharing App, the tests run just fine using the iOS simulator. However, if I close out of the remote connection while the tests are running, ui tests that involve typing text will fail with the following error when attempting to type (all other tests / ui tests pass with flying colours):

Assertion Failure: Timed out waiting for key event to complete

This obviously causes some problems when Jenkins is automatically running the tests for us, since we don't always want to be remotely logged into the machine.

I feel like this has something to do with the software keyboard of the simulator but am failing to see why it would be an issue. Does the mac need to have some sort of display output connected in order for the software keyboard to exist or some such thing? Would connecting a monitor to the machine (even if it's not really being used) cause the tests to pass? Why would this be the case?

Villeneuve answered 30/11, 2015 at 22:31 Comment(1)
Not sure if it helps, but I remember that Mac Minis don't take full advantage of the GPU when running headless. I've heard of a few workarounds but never got around to trying any.Stamen
B
5

This problem could be sorted out by turning off the connected hardware keyboard in the simulator settings for few.

You may also want to try that UI Testing Failure - Neither element nor any descendant has keyboard focus on TextView

Berlyn answered 23/2, 2016 at 8:27 Comment(1)
"turning off the connected hardware keyboard" is the key. Oh, apple should realy work on that.Ladonna
V
1

Xcode 10 still has the same issue after you presented a CNContactViewController instance.

Avoid write those cases which need call CNContactViewController` instance.

Or there is a workaround:

app.keys["1"].tap()
app.keys["2"].tap()
app.keys["3"].tap()
Vlf answered 11/9, 2019 at 1:44 Comment(0)
P
0

I am using xcode 8.2.1 and running tests on ios 9.3 versions. One simple hack is to add a sleep for 2-5 secs after tapping on the text box and before typing on it. Though, this is not a permanent solution.

ANOTHER RELIABLE SOLUTION

Unselect all keyboard preferences in settings before running the tests.

"KeyboardAllowPaddle": false,
"KeyboardAssistant": false,
"KeyboardAutocapitalization": false,
"KeyboardAutocorrection": false,
"KeyboardCapsLock": false,
"KeyboardCheckSpelling": false,
"KeyboardPeriodShortcut": false,
"KeyboardPrediction": false,
"KeyboardShowPredictionBar": false
Parke answered 16/5, 2017 at 10:7 Comment(0)
L
0

You can paste it on the TextField like:

extension XCUIApplication {
  // The following is a workaround for inputting text in the
  //simulator when the keyboard is hidden
  func setText(_ text: String, on element: XCUIElement?) {
    if let element = element {
    UIPasteboard.general.string = text
    element.doubleTap()
    self.menuItems["Select All"].tap()
    self.menuItems["Paste"].tap()
    }
  }
}

Run with:

self.app?.setText("Lo", on: self.app?.textFields.firstMatch)
Limousin answered 28/11, 2019 at 22:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.