XCTestCase:等待应用程序闲置

我的UItesting失败,因为testing等待无尽,直到应用闲置。 我看不到背景中有什么事情发生,比如加载微调。

它只发生在一个选项卡上。 所有其他选项卡都可以打开,但屏幕3上的testing失败。在屏幕3上捕捉testing后,单击另一个选项卡,testing将继续并成功完成。

有任何想法吗?

- (void)testExample { XCUIElementQuery* tabBarsQuery = self.app.tabBars; [tabBarsQuery.buttons[@"Screen2"] tap]; [tabBarsQuery.buttons[@"Screen3"] tap]; [tabBarsQuery.buttons[@"Screen1"] tap]; [tabBarsQuery.buttons[@"Screen4"] tap]; } 

也许你有一些animation或一些其他的背景(或前景)活动,频繁更新主线程上的用户界面。 这导致应用永远不会“静止” – 至less在这个标签上。 在我们的应用程序中,我们有UIViewanimation和选项Repeat。 CPU使用情况良好,并不是电池消耗,但每次都会使testing失败。 禁用animation修复了这个问题。 我无法find迫使testing不要等待空闲的方法,所以我们最终使用#ifdef为UItesting目标使用运行时参数禁用animation如下所述: https : //stackoverflow.com/a/一十六万八千九百九十六分之三千三百四十六万六千零三十八