Charlie Seligman Charlie Seligman - 1 year ago 96
iOS Question

Xcodes UI Testing showing out of date page info

Currently have the following method:

func waitForOptionalElement(explicitElement: XCUIElement, timeout: Int) {
var waitedDuration = 0
while waitedDuration < timeout {
if explicitElement.exists {

This method is aimed at waiting until an object appears on the screen. The trouble I have is that if explicityElement is not present on the screen when the method is called, then explicitElement.exists always returns a false (even when the object appears). It is like the explicitElement is not refreshed when the page changes, but keeps checking the original view rather than any updated view.

If I call the explicitElement in full e.g. XCUIApplication().staticTexts["Error message"].exists then that will come back true. Its as if you need to call XCUIApplication()... to get an updated view of the current page?

Anyone know any clever ways round this?

Answer Source

It may be more appropriate to use expectationForPredicate.

expectationForPredicate(NSPredicate(format: "exists == true"), evaluatedWithObject: XCUIApplication().staticTexts["Error message"], handler: nil)
waitForExpectationsWithTimeout(15.0, handler: nil)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download