Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save quangDecember/37e2902e4d74855349921eefc96f13ab to your computer and use it in GitHub Desktop.
Save quangDecember/37e2902e4d74855349921eefc96f13ab to your computer and use it in GitHub Desktop.
wait for existence in UI testing
import XCTest
class BaseTestCase: XCTestCase {
let app = XCUIApplication()
// ...
func waitforExistence(element: XCUIElement, file: String = #file, line: UInt = #line) {
let exists = NSPredicate(format: "exists == true")
expectation(for: exists, evaluatedWith: element, handler: nil)
waitForExpectations(timeout: 30) {(error) -> Void in
if (error != nil) {
let message = "Failed to find \(element) after 30 seconds."
self.recordFailure(withDescription: message,
inFile: file, atLine: Int(line), expected: true)
}
}
}
}
@aehlke
Copy link

aehlke commented May 18, 2023

how is this better than waitForExistence? is it faster?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment