XCTest:在 iOS Safari 浏览器上禁用动画

问题描述 投票:0回答:1

我正在开发 XCUITest,以自动化 iPhone 中 Safari 浏览器中的某些功能。 我间歇性地看到以下日志,并且自动化被卡住了。

t =   504.16s         Wait for app to idle
t =   625.29s         App animations complete notification not received, will attempt to continue.
t =   625.30s         Synthesize event
t =   625.67s         Wait for app to idle

互联网上的所有答案都建议使用

UIView.setAnimationsEnabled(false)
。我尝试了这个解决方案,但这并没有多大帮助。

我的问题是:

UIView.setAnimationsEnabled(false)
仅在应用程序中禁用动画还是这也适用于Safari浏览器中的网站? 如果不行的话还有其他解决办法吗?

参考 - Xcode 8 UI 测试花费很长时间

xctest xcuitest xcuiautomation
1个回答
0
投票

在 iOS 应用程序的 UI 测试中禁用等待空闲状态找到了答案。

TestBase
是我的基类,从
XCTestCase

扩展而来
private func disableWaitForIdle() {
        if !TestBase.swizzledOutIdle {
            let original = class_getInstanceMethod(objc_getClass("XCUIApplicationProcess") as? AnyClass, Selector(("waitForQuiescenceIncludingAnimationsIdle:")))
            let replaced = class_getInstanceMethod(type(of: self), #selector(TestBase.replace))!
            method_exchangeImplementations(original!, replaced)
            TestBase.swizzledOutIdle = true
        }
}

用途:

override func setUp() {
        Self.logger.info("Running test method setup before \(self.name)...")
        disableWaitForIdle()
        super.setUp()
        continueAfterFailure = false
        UIView.setAnimationsEnabled(false)
}
© www.soinside.com 2019 - 2024. All rights reserved.