ios - Xcodes UI 测试显示过时的页面信息

标签 ios xcode automation xcode-ui-testing

目前有以下方法:

func waitForOptionalElement(explicitElement: XCUIElement, timeout: Int) {
    var waitedDuration = 0
    while waitedDuration < timeout {
        if explicitElement.exists {
            break
        }
        waitedDuration++
        sleep(1)
    }
}

这个方法的目的是等待一个对象出现在屏幕上。我遇到的问题是,如果调用方法时 explicityElement 不在屏幕上,则 explicitElement.exists 总是返回 false(即使对象出现)。这就像 explicitElement 在页面更改时不会刷新,而是继续检查原始 View 而不是任何更新的 View 。

如果我完整地调用 explicitElement,例如 XCUIApplication().staticTexts["错误信息"].exists 然后返回 true。就好像您需要调用 XCUIApplication()... 来获取当前页面的更新 View ?

有人知道解决这个问题的巧妙方法吗?

最佳答案

expectationForPredicate可能更合适.

expectationForPredicate(NSPredicate(format: "exists == true"), evaluatedWithObject: XCUIApplication().staticTexts["Error message"], handler: nil)
waitForExpectationsWithTimeout(15.0, handler: nil)

关于ios - Xcodes UI 测试显示过时的页面信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39164276/

相关文章:

ios - 为什么 UIFont sizeWithFont 在其计算中包含空格?

ios - 使用 TeSTFlight 进行测试时,应用程序在闪屏后崩溃

jquery - 创建一个 jquery Margin 加法器类

automation - IE9,使用 CertEnroll.dll 时自动化服务器无法创建对象错误

iOS 为 initWithNibName 生成的函数结构

ios - 处理 NSDateFormatter 语言环境 "feature"的最佳方法是什么?

ios - SpriteKit 默认项目 - 为什么 View 起源于屏幕之外?

Xcode 12. 类型 'AVCapturePhotoOutput' 的值没有成员 'supportedFlashModes'

xcode - Xcode 测试导航器中保留已删除的测试

android - 数据传递到 Android 中的另一个应用程序