XCTestCase:等待应用程序空闲 [英] XCTestCase: Wait for app to idle

查看:259
本文介绍了XCTestCase:等待应用程序空闲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的UI测试失败,因为测试等待无休止,直到应用程序空闲。我无法看到后台发生任何事情,比如加载微调器。

My UI-test fails because the test waits endless until the app idles. I can not see that there is anything happening in the background, like a loading spinner.

它只出现在一个选项卡上。所有其他选项卡都是可点击的,但测试在屏幕3上失败。在屏幕3上测试后,点击另一个选项卡,测试重新开始并成功完成。

It just occurs on one tab. All others tabs are tapable but the test fails on Screen 3. I I click on another tab after the test is caught on Screen 3 the test resumes and finishes successfully.

任何想法?

- (void)testExample
{

    XCUIElementQuery* tabBarsQuery = self.app.tabBars;

    [tabBarsQuery.buttons[@"Screen2"] tap];
    [tabBarsQuery.buttons[@"Screen3"] tap];
    [tabBarsQuery.buttons[@"Screen1"] tap];
    [tabBarsQuery.buttons[@"Screen4"] tap];

}


推荐答案

也许你有一些动画或一些其他背景(或前景)活动,经常在主线程上更新你的UI。这导致应用程序永远不会静默 - 至少在此选项卡上。在我们的应用程序中,我们有UIView动画,可选择Repeat。 CPU使用情况很好并且不是电池耗尽,但它每次都使测试失败。禁用动画修复了问题。我找不到一种方法来强制测试不要等待空闲,所以我们最终使用#ifdef禁用动画用于UI测试目标,使用运行时参数,如下所述: https://stackoverflow.com/a/33466038/168996

Perhaps you have some animation or some other background (or foreground) activity that updates your UI on the main thread frequently. This causes the app to never be "quiesce" - at least on this tab. In our application we had UIView animation with option Repeat. CPU usage was fine and it wasn't a battery drain, but it made the test fail every time. Disabling the animation fixed the issue. I couldn't find a way to force the test not to wait to be idle, so we ended up disabling the animation using #ifdef for the UI test target using runtime arguments as described here: https://stackoverflow.com/a/33466038/168996

这篇关于XCTestCase:等待应用程序空闲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆