Harden test harness and UI suite
This commit is contained in:
@@ -59,6 +59,33 @@ class BaseUITestCase: XCTestCase {
|
||||
screenshot.lifetime = .keepAlways
|
||||
add(screenshot)
|
||||
}
|
||||
|
||||
/// Polls until the condition becomes true or the timeout expires.
|
||||
@discardableResult
|
||||
func waitUntil(
|
||||
timeout: TimeInterval = BaseUITestCase.defaultTimeout,
|
||||
pollInterval: TimeInterval = 0.2,
|
||||
_ message: String? = nil,
|
||||
file: StaticString = #filePath,
|
||||
line: UInt = #line,
|
||||
condition: @escaping () -> Bool
|
||||
) -> Bool {
|
||||
let deadline = Date().addingTimeInterval(timeout)
|
||||
|
||||
while Date() < deadline {
|
||||
if condition() {
|
||||
return true
|
||||
}
|
||||
|
||||
let remaining = deadline.timeIntervalSinceNow
|
||||
let interval = min(pollInterval, max(0.01, remaining))
|
||||
RunLoop.current.run(until: Date().addingTimeInterval(interval))
|
||||
}
|
||||
|
||||
let success = condition()
|
||||
XCTAssertTrue(success, message ?? "Condition was not met within \(timeout)s", file: file, line: line)
|
||||
return success
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Wait Helpers
|
||||
|
||||
Reference in New Issue
Block a user