Bartłomiej Semańczyk Bartłomiej Semańczyk - 27 days ago 4
iOS Question

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

But this is horrible since I cannot put there
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?


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)