【问题标题】:Failed to get main window after 30 retries: kAXErrorServerNotFound重试 30 次后无法获取主窗口:kAXErrorServerNotFound
【发布时间】:2017-11-24 10:20:52
【问题描述】:

我有一套 26 项测试。有时某些测试,任何测试,都会失败并出现以下错误:

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

使用 Xcode 8 时,测试在报告中未显示为失败,但在使用 Xcode 9 时显示为失败。使用 Xcode 9 时问题类似,但日志不同。

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

报告中的屏幕截图显示应用程序已启动并且似乎处于空闲状态。

更新

我在 sample project 中重现了这个问题,这是一个带有标签栏视图控制器的简单应用程序。

更新

Xcode 9 Beta 6 的发行说明中似乎存在与此相关的已知问题

xcodebuild 测试可能会因“Domain=XCTestManagerErrorDomain Code=12”而间歇性失败 “重试 30 次后无法获取主窗口”。 (29122169)

解决方法:重试测试。

希望这个问题能在 Xcode 9 最终版本发布之前得到解决

【问题讨论】:

    标签: xcode xctest xcode-ui-testing ui-testing xcode9-beta


    【解决方案1】:

    我在 Xcode 8.3.2 上一直在为这个 exact 同样的问题而苦苦挣扎 — 很遗憾听到 Xcode 9 beta 还没有解决这个问题:(

    到目前为止,唯一可靠的修复方法是重置 iOS 模拟器设备。例如:

    osascript -e 'tell application "Simulator" to quit'
    xcrun simctl erase all
    

    如果您知道自己的设备 ID,则可以将其重置:

    xcrun simctl erase DEVICE_ID
    

    (不用说,您可以将这些命令包装在一个简单的 shell 脚本中,并在出现此问题时从终端运行它。)

    【讨论】:

    • 谢谢。不过,我正在设备上运行我的测试。有什么解决办法吗?
    • 嗯...您可以尝试从设备中删除应用程序(和 UI 测试)。但这在过去并不总是对我有用。
    猜你喜欢
    • 2020-03-04
    • 2016-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-08
    • 1970-01-01
    相关资源
    最近更新 更多