Failed to get main window after 30 tries: kAXErrorServerNotFound
I have a suite of 26 tests. Sometimes some tests, any tests, fail with the following error:
Test Case ...
t = 0.00s Start Test at 2017-06-21 13:41:15.265
t = 0.00s Set Up
t = 0.11s Launch com.company.MyApp
t = 4.06s Wait for app to idle
t = 10.27s Unable to monitor animations
t = 16.45s Unable to monitor event loop
t = 17.67s Snapshot accessibility hierarchy for com.company.MyApp
t = 23.84s Assertion Failure: <unknown>:0: Failure getting snapshot Error Domain=XCTDaemonErrorDomain Code=12 "Failed to get main window after 30 retries: kAXErrorServerNotFound (see <rdar://problem/15530121>)" UserInfo={NSLocalizedDescription=Failed to get main window after 30 retries: kAXErrorServerNotFound (see <rdar://problem/15530121>)}
t = 23.85s Tear Down
Tests are not displayed with an error in the report when using Xcode 8, but they apply when using Xcode 9. With Xcode 9, the problem is similar, but the logs are different.
t = 0.00s Start Test at 2017-06-22 14:17:00.716
t = 0.08s Set Up
t = 0.18s Open com.company.MyApp
t = 0.26s Launch com.company.MyApp
t = 3.39s Wait for com.company.MyApp to idle
t = 9.58s Unable to monitor animations
t = 15.76s Unable to monitor event loop
t = 16.90s Snapshot accessibility hierarchy for app with pid 18003
t = 23.17s Tap "More" Button
t = 23.17s Wait for com.company.MyApp to idle
t = 29.41s Unable to monitor animations
t = 35.59s Unable to monitor event loop
t = 35.61s Find the "More" Button
t = 35.61s Snapshot accessibility hierarchy for app with pid 18003
t = 41.92s Wait for com.company.MyApp to idle
t = 48.16s Unable to monitor animations
t = 54.34s Unable to monitor event loop
t = 55.36s Find the "More" Button (retry 1)
t = 55.37s Snapshot accessibility hierarchy for app with pid 18003
t = 61.69s Wait for com.company.MyApp to idle
t = 67.92s Unable to monitor animations
t = 74.10s Unable to monitor event loop
t = 75.12s Find the "More" Button (retry 2)
t = 75.12s Snapshot accessibility hierarchy for app with pid 18003
t = 81.44s Wait for com.company.MyApp to idle
t = 87.66s Unable to monitor animations
t = 93.86s Unable to monitor event loop
t = 94.00s Assertion Failure: report.feature:11: Failed to get main window after 30 retries: kAXErrorServerNotFound (see <rdar://problem/15530121>)
t = 94.21s Find the Window
t = 94.21s Snapshot accessibility hierarchy for app with pid 18003
t = 101.35s Find the Window (retry 1)
t = 101.35s Snapshot accessibility hierarchy for app with pid 18003
t = 108.53s Find the Window (retry 2)
t = 108.53s Snapshot accessibility hierarchy for app with pid 18003
t = 114.79s Assertion Failure: report.feature:10: Failed to get main window after 30 retries: kAXErrorServerNotFound (see <rdar://problem/15530121>)
t = 114.79s Tear Down
Screenshots in the report show that the application is running and appears to be inactive.
Update
I have reproduced the problem in a sample project , which is a simple application with a tab bar view controller.
Update
The Xcode 9 Beta 6 release notes seem to have a known issue regarding this
The xcodebuild test may fail with the following error: "Domain = XCTestManagerErrorDomain Code = 12" Failed to get main window after 30 attempts. "(29122169)
Temporary solution . Try again.
Hopefully this will be fixed before the final release of Xcode 9
source to share
I ran into this same issue on Xcode 8.3.2 - sad to hear that Xcode 9 beta hasn't fixed it yet :(
The only reliable fix so far has been resetting the iOS simulator (s). For example:
osascript -e 'tell application "Simulator" to quit'
xcrun simctl erase all
If you know your device ID, you can reset simply:
xcrun simctl erase DEVICE_ID
(It goes without saying that you can wrap these commands in a simple shell script and run it from your terminal when this problem appears.)
source to share