Skip to content

Instantly share code, notes, and snippets.

@chrisvasselli
Created June 25, 2020 20:15
Show Gist options
  • Save chrisvasselli/adb01e56b7e11390634931bd5d95710c to your computer and use it in GitHub Desktop.
Save chrisvasselli/adb01e56b7e11390634931bd5d95710c to your computer and use it in GitHub Desktop.
public func XCTAssertSoon(_ expression: @autoclosure () throws -> Bool, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line, waitTime: TimeInterval = 3) {
let startTime = Date()
repeat {
let success = (try? expression()) ?? false
if success {
return
}
else {
Thread.sleep(forTimeInterval: 1)
}
}
while Date().timeIntervalSince(startTime) < waitTime
XCTAssert((try? expression()) ?? false, message(), file: file, line: line)
}
extension XCUIElement {
var existsSoon: Bool {
return self.exists || self.waitForExistence(timeout: 3)
}
func tapSoon() {
XCTAssert(self.existsSoon)
self.tap()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment