Skip to content

Instantly share code, notes, and snippets.

@yannxou
Created December 11, 2024 08:48
Show Gist options
  • Save yannxou/b439b02c4b2efc73e99a7189832eed89 to your computer and use it in GitHub Desktop.
Save yannxou/b439b02c4b2efc73e99a7189832eed89 to your computer and use it in GitHub Desktop.
Waiting for XCUIElement attributes
// Source: https://medium.com/@anthony.prokuda/how-to-locate-and-wait-for-an-element-in-xcuitest-a-powerful-approach-105b81628986
extension XCUIElement {
func wait<U>(
attribute keyPath: KeyPath<XCUIElement, U>,
is comparisonOperator: NSComparisonPredicate.Operator,
value: U,
timeout: TimeInterval = 10
) -> XCUIElement? {
let predicate = NSPredicate.keyPath(
keyPath,
is: comparisonOperator,
value: value
)
let expectation = XCTNSPredicateExpectation(predicate: predicate, object: self)
let result = XCTWaiter.wait(for: [expectation], timeout: timeout)
return result == .completed ? self : nil
}
}
let progressLabel = app.staticTexts["PROGRESS_LABEL"].firstMatch.wait(attribute: \.label, is: .equalTo, value: "100%")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment