Skip to content

Instantly share code, notes, and snippets.

@leodutra
Created March 27, 2020 02:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leodutra/5f7bd6e5fd3911535acce11fc3c7685e to your computer and use it in GitHub Desktop.
Save leodutra/5f7bd6e5fd3911535acce11fc3c7685e to your computer and use it in GitHub Desktop.
waitForHittable Swift UI Test
static func waitForHittable(_ element: XCUIElement, timeout: TimeInterval) -> Bool {
let startTime = Date().timeIntervalSinceReferenceDate
let remainingTime = { () -> Double in
let diff = timeout - (Date().timeIntervalSinceReferenceDate - startTime)
return diff > 0 ? diff : 0
}
if element.waitForExistence(timeout: remainingTime()) {
repeat {
if element.isHittable {
return true
}
sleep(1)
}
while remainingTime() > 0
}
return false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment