Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UI test fails when it types text into a text view when run by an Xcode bot

I have the following XCTest UI test that types text into a text view.

let textView = app.textViews.elementBoundByIndex(0)
textView.tap()
textView.typeText("Hello world")

When run as an Xcode bot it shows the following error for the typeText call.

Assertion: UI Testing Failure - failed: Timed out waiting for key event to complete

enter image description here

Interestingly, when I run it manually from the Xcode on the same computer the test passes. This test also passed in Xcode bot before upgrade to Xcode 7.1 / iOS 9.1. What can be the source of the problem?

Here is an isolated demo with the UI test: https://github.com/exchangegroup/UITestTextViewDemo

iOS 9.1 Simulator, OS X 10.11.1 (15B42), Xcode 7.1 (7B91b), OS X Server 5.0.15 (15S4033)

Reported to Apple.

like image 409
Evgenii Avatar asked Oct 27 '15 02:10

Evgenii


2 Answers

I believe the underlying issue is that "Connect Hardware Keyboard" is turned on by default. Even if you turn it off for the main user, the _xcsbuildd user still uses the default. I was able to solve the problem by adding a pre test action to the scheme with the following script:

if [ `defaults read com.apple.iphonesimulator ConnectHardwareKeyboard` -eq 1 ]
 then
  defaults write com.apple.iphonesimulator ConnectHardwareKeyboard -bool false
  killall "Simulator"
fi

enter image description here

like image 66
David Beck Avatar answered Oct 16 '22 16:10

David Beck


I found a solution for my case and I hope it helps you as well.

In my setUp() and tearDown() (seems redundant I know) I put XCUIApplication().terminate(). This is ensuring that the app is terminated before running the next test and it seems to be doing the job.

override func setUp() {
    XCUIApplication().terminate()
    super.setUp()
    continueAfterFailure = false
    XCUIApplication().launch()
}
override func tearDown() {
    super.tearDown()
    XCUIApplication().terminate()
}

I filed a bug with Apple but for the time being this is getting me around the error that you were seeing. Hope that helps!

like image 38
cakes88 Avatar answered Oct 16 '22 16:10

cakes88