Search code examples
iosxcodexcuitestgui-testing

Xcode UITest app quits unexpectedly when selecting an element


I am testing a particular screen. I must access an element in this case a button:

let button = app.buttons["Example"]

When this statement is executed, the app being tested quits. The UI test error reads:

testFirstOrderForNewUser(): Failed to Error Domain=com.apple.dt.xctest.ui-testing.error Code=10001 "Application com.myapp.debug is not running" UserInfo={NSLocalizedDescription=Application com.myapp.debug is not running}: Application com.myapp.debug is not running

Have you experienced this before or know what causes this unfortunate behavior?

This happens to a handful of specific screens and elements in the app. Using the test recording feature, interaction works through this section. However, the ui queries are not emitted. Or Xcode will sputter out:

enter image description here

Or Xcode will just freeze with the customary color-wheel.

Context: Xcode 14.3.1 distribution.

I have tried adding an element to the application's UIWindow to see if it is a problem with view hierarchy.


Solution

  • The cause of this problem is using an image in a NSTextAttachment in a UITextView in another area of the screen. It is only this combination. The attachment on a UILabel attributed string does not cause this problem. This breaks automation for me. The solution is to use a different solution for labels with trailing accessories.