Last active
August 29, 2015 14:26
-
-
Save kcharwood/0a57d7a207aba1d578da to your computer and use it in GitHub Desktop.
With Xcode 7 Beta 4, Apple gave us a way to wait asynchronously during UI tests. This gist lets you wait on an Activity Indicator to finish.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import XCTest | |
extension XCTestCase { | |
func waitForActivityIndicatorToStartAndFinishSpinning(activityIndicatorElement: XCUIElement, timeout: NSTimeInterval = 30.0) { | |
let inProgressPredicate = NSPredicate(format: "label = 'In progress'") | |
self.expectationForPredicate(inProgressPredicate, evaluatedWithObject: activityIndicatorElement, handler: nil) | |
self.waitForExpectationsWithTimeout(timeout, handler: nil) | |
let progressHaltedPredicate = NSPredicate(format: "label = 'Progress halted'") | |
self.expectationForPredicate(progressHaltedPredicate, evaluatedWithObject: activityIndicatorElement, handler: nil) | |
self.waitForExpectationsWithTimeout(timeout, handler: nil) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment