How to wait under UITests in Xcode until some view will be visible for tap?
Asked Answered
A

1

5

Sometimes under UITests in Xcode the compiler try to tap the button before it is loaded and presented. Then arise a problem like no matched found for....

But the simple solution for this is:

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

But this is horrible since I cannot put there 0.1 as a parameter. And it makes me annoying to wait 1 second before a lot of buttons.

Is there a way to wait until it is visible for uitests?

Andrewandrewes answered 30/9, 2016 at 9:54 Comment(0)
L
9

You should create an XCTestExpectation and wait for it to be fulfilled

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

mybutton.tap()
Lacto answered 30/9, 2016 at 10:9 Comment(1)
For Swift 3 you can leave handler parameters.Liebig

© 2022 - 2024 — McMap. All rights reserved.