【问题标题】:How to wait under UITests in Xcode until some view will be visible for tap?如何在 Xcode 中的 UITests 下等待,直到可以看到某些视图以供点击?
【发布时间】:2016-09-30 09:54:20
【问题描述】:

有时在 Xcode 中的 UITests 下,编译器会在加载和呈现按钮之前尝试点击按钮。然后出现no matched found for...之类的问题。

但是解决这个问题的简单方法是:

sleep(1) //wait 1 second and give `mybutton` time to load and be accessible for uitests
mybutton.tap()

但这太可怕了,因为我不能把0.1 作为参数放在那里。在很多按钮之前等待 1 秒让我很烦。

有没有办法等到它对 uitests 可见?

【问题讨论】:

    标签: ios swift xcode-ui-testing


    【解决方案1】:

    您应该创建一个XCTestExpectation 并等待它完成

    expectationForPredicate(NSPredicate(format: "hittable == true"), evaluatedWithObject: mybutton, handler: nil)
    waitForExpectationsWithTimeout(10.0, handler: nil)
    
    mybutton.tap()
    

    【讨论】:

    • 对于 Swift 3,您可以留下 handler 参数。
    猜你喜欢
    • 1970-01-01
    • 2018-01-27
    • 1970-01-01
    • 2016-07-17
    • 2016-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多