Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIAutomation and XCTestCase: how to wait for a button to activate

I'm writing a UIAutomation test case and I need to wait for the user to be activated before continuing. There doesn't seem to be a nice way to check for a button to change to the enabled state.

Whats the best was to wait for something to happen in the UI before checking it's status?

Neither dispatch_after nor NSTimer seem to work. They just block then fail.

like image 780
Brian Avatar asked Jul 08 '15 18:07

Brian


1 Answers

It's actually pretty easy if you use NSPredicates and expectations. You can even set a timeout value. This example shows you how to do it with a 5 second timeout.

let exists = NSPredicate(format:"enabled == true")
expectationForPredicate(exists, evaluatedWithObject: app.tables.textFields["MY_FIELD_NAME"], handler: nil)
waitForExpectationsWithTimeout(5, handler: nil)
like image 192
Etienne Avatar answered Nov 04 '22 18:11

Etienne