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
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.
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
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With