XCTest / Xcode UI Test - Simulator Error Causing Test Failures


Starting on 10/20/17, did something change regarding the iOS simulators that are used for the Xcode Test step? All of my test jobs suddenly started failing with this error:

“Neither element nor any descendant has keyboard focus”

This error occurs when XCTest / simulator cannot access the keyboard when attempting to type some value into a text field element. Until now (for around 6 months or so). In order to prevent this from happening, you must go to (iOS Simulator menu) Hardware > Keyboard > then disable “Connect Hardware Keyboard”.

As this is a CI service , I was accomplishing this remotely by running a script before running the Xcode Test step:

defaults write com.apple.iphonesimulator ConnectHardwareKeyboard -bool false

This was working beautifully, but for some reason this is no longer accomplishing the desired effect. I honestly have no idea how other people have been getting around this without running this pre-test script, when using Xcode UI Tests.

Any expedient help would be really appreciated. Thanks a lot.

1 Like

Hi @juliancmg,

Which stack?

In general, on Oct 20 nothing changed. We did roll out the usual weekly updates on 21st, you can find the details here: Weekly Virtual Machine / Stack updates - 2017.10.21

Hi @viktorbenei, thanks for the reply, this is on the Xcode 9.0.x stack. It looks like Xcode was updated to 9.0.1 on this stack a couple of days ago? (From Apple release notes: Updated Simulator to use the iOS runtime used on iPhone X.) I will try updating locally to 9.0.1 to see if I can reproduce the issue I outlined above.

I’m trying the same workflow on the 9.1 stack to see if I get any different results.

Have you guys encountered anyone else running into issues with their iOS UI tests running properly?

Not that I’m aware of, no.

Let us know how it goes! :slight_smile:

Did you try it on the Xcode 9.1 final stack @juliancmg? Did that help?

Hey, sorry to zombie this thread, but we’re having the same issue with our builds. They work locally and in general we don’t get this problem on our dev machines, but when we do it’s because the software keyboard isn’t being shown.

With Xcode 12 beta / iOS 14 simulators it looks like the software keyboard is disabled by default, but I can’t work out any way to programatically enable it.

Any ideas?

Thanks in advance!

Hi @brindyddg! In case it’s still happening, can you send us some build examples with access enabled? Thanks!

Hi @bitce - thanks for following up. It looks OK now. Thanks!

Did something change?

That’s great news! Well, environments are updated weekly (which can be checked here) but it would be hard to pinpoint what change could have solved this without understanding the cause :thinking:

Well this release of iOS and Xcode hasn’t gone as smoothly as normal for Apple. Maybe it was something with the GM seed? Anyway, it’s working now so all good. Thanks again!