On iOS 18, when XCUITest encounters an "Application has not loaded accessibility" error after the 60 second timeout, it performs an undocumented auto-recovery ("Setting up automation session") instead of halting the test as documented. This leaves the XCUITest framework in a corrupted state, causing subsequent tests in the same session to fail with unexpected behavior.
Expected Behavior (per Apple documentation):
Any failure in the launch sequence will be reported as a test failure and the test will be halted at that point.
Actual Behavior:
XCUITest waits 60 seconds for accessibility to load Logs "Application has not loaded accessibility" error Instead of halting, performs "Setting up automation session" (auto-recovery) Test continues with corrupted framework state Subsequent tests in the same session fail with phantom element queries
Steps
Run XCUITest suite on a real iOS 18 device
Have an app with moderately heavy initialization (e.g., synchronous network operations during bootstrap) Observe intermittent "accessibility not loaded" errors When error occurs, subsequent tests fail with unexpected behavior
Test Logs Evidence
First test (accessibility failure + recovery):
t = 11.11s Wait for accessibility to load
t = 71.14s Capturing diagnostic spindump
t = 76.24s Assertion Failure: Application 'com.example.app' has not loaded accessibility
t = 76.26s Setting up automation session ← Undocumented recovery
t = 77.29s Tear Down
Second test (corrupted state):
t = 35.01s Tap "signin-button"
t = 35.55s Waiting for "bannerButtonStackFirstItem" ← Query NOT in test code!
t = 40.58s Assertion Failure: Failed to find element
The second test executes element queries that do not exist in its source code, indicating leaked/corrupted state from the previous test's failed recovery.
Note: The tearDown() method terminates the app but cannot reset the internal state of the XCUITest framework itself, so corruption persists across tests.
We are observing this behavior consistently on iOS 18 real devices. We would like to know:
Is this a known issue with XCUITest on iOS 18?
Is anyone experiencing similar "accessibility not loaded" failures followed by auto-recovery?
Is the "Setting up automation session" recovery behavior intentional or a bug?
Is there a recommended workaround to prevent framework state corruption between tests?