Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 201
Bartłomiej Semańczyk Avatar asked Sep 30 '16 09:09

Bartłomiej Semańczyk


1 Answers

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()
like image 143
Tomas Camin Avatar answered Sep 23 '22 20:09

Tomas Camin