Created
June 25, 2020 20:15
-
-
Save chrisvasselli/adb01e56b7e11390634931bd5d95710c to your computer and use it in GitHub Desktop.
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
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