代码之家  ›  专栏  ›  技术社区  ›  Bartłomiej Semańczyk

如何在Xcode中的UITests下等待,直到可以点击某些视图?

  •  5
  • Bartłomiej Semańczyk  · 技术社区  · 10 年前

    有时在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 作为参数。在很多按钮前等待一秒钟让我很恼火。

    有没有办法等到uitest可以看到它?

    1 回复  |  直到 10 年前
        1
  •  9
  •   Tomas Camin    10 年前

    您应该创建一个 XCTestExpectation 等待它实现

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