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?

David Bagwell
  • 318
  • 3
  • 12
  • 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](http://blog.macsales.com/25997-headless-mac-video-accelerator-new-solution-to-old-problem) [workarounds](http://www.macrumors.com/2015/11/10/newertech-hdmi-headless-adapter-for-mac-mini/) but never got around to trying any. – Joe Masilotti Dec 01 '15 at 03:20

4 Answers4

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

Community
  • 1
  • 1
Yogesh Khatri
  • 319
  • 3
  • 7
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()
beimenjun
  • 753
  • 7
  • 6
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
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)