Skip to content

Instantly share code, notes, and snippets.

@kcharwood
Last active August 29, 2015 14:26
Show Gist options
  • Save kcharwood/0a57d7a207aba1d578da to your computer and use it in GitHub Desktop.
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.
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