Created
December 11, 2024 08:48
-
-
Save yannxou/b439b02c4b2efc73e99a7189832eed89 to your computer and use it in GitHub Desktop.
Waiting for XCUIElement attributes
This file contains hidden or 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
// 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