在iOS应用的UI测试中禁用等待空闲状态 [英] Disabling waiting for idle state in UI testing of iOS apps

查看:111
本文介绍了在iOS应用的UI测试中禁用等待空闲状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,此问题与此相同: XCTestCase:等待应用程序空闲

Basically the problem is the same as this one: XCTestCase: Wait for app to idle

我在视图中使用的是永久重复的背景动画". Xcode/iOS的!@#$#$& @ UI测试要等待所有UIView动画结束,然后才认为应用程序处于空闲状态并继续执行诸如轻按按钮等操作.我们已经设计了该应用. (特别是,我们有一个带有UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse选项动画的按钮,因此它永远不会停止.)

I am using perpetually repeating "background animations" in my views. The !@#$#$&@ UI testing of Xcode/iOS wants to wait for all UIView animations to end before it considers the app idle and goes on with stuff like tapping buttons etc. It just doesn't work with the way we've designed the app(s). (Specifically, we have a button that is animated with UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse options, so it never stops.)

但是我认为可能有某种方法可以关闭和/或缩短状态等待应用空闲".在那儿?如何?还有其他解决方法吗?

But I'm thinking there might be some way to turn off and/or shorten the state "Wait for app to idle". Is there? How? Is there any other way around this?

推荐答案

不幸的是,使用Apple的UI测试,您无法将等待应用空闲"或轮询其他网络活动,但是您可以使用环境变量来禁用其中的动画您的应用程序可以使测试更加稳定.在测试之前的设置方法中,设置一个这样的环境变量.

Unfortunately using Apple's UI Testing you can't turn 'wait for app to idle' or poll other network activity, however you can use environment variables to disable animations in your app to make the tests more stable. In your setup method before your test set an environment variable like this.

override func setUp() {
    super.setUp()
    continueAfterFailure = false
    let app = XCUIApplication()
    app.launchEnvironment = ["UITEST_DISABLE_ANIMATIONS" : "YES"]
    app.launch()
}

现在在您的源代码中:

if (ProcessInfo.processInfo.environment["UITEST_DISABLE_ANIMATIONS"] == "YES") {
    UIView.setAnimationsEnabled(false)
}

如果只希望它禁用特定视图的动画,或者将其放置在委托文件中以禁用整个应用程序的动画,则可以将其放置在特定视图中.

You can place that check in a specific view if you only want it to disable animations for that specific view or in a delegate file to disable animations throughout the app.

这篇关于在iOS应用的UI测试中禁用等待空闲状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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