Skip to content

Commit a450c81

Browse files
authored
Add XCUIElement helper methods to wait for an NSPredicate (#6)
2 parents 42a8b86 + 79f5a39 commit a450c81

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

Sources/XCUITestHelpers/XCUIElement+Async.swift

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,23 @@ extension XCUIElement {
1212
// Avoid unnecessary waiting if the element is already hittable
1313
guard isHittable == false else { return true }
1414

15-
let result = XCTWaiter.wait(
16-
for: [
17-
XCTNSPredicateExpectation(
18-
predicate: NSPredicate(format: "isHittable == true"),
19-
object: self
20-
)
21-
],
15+
return waitFor(predicateString: "isHittable == true", timeout: timeout) == .completed
16+
}
17+
18+
/// Uses the given `String` to create an `NSPredicate` and waits for it to be true on `self` for
19+
/// the given `timeout` (defaults to 3 seconds)
20+
@discardableResult
21+
public func waitFor(predicateString: String, timeout: TimeInterval = 3.0) -> XCTWaiter.Result {
22+
waitFor(predicate: NSPredicate(format: predicateString), timeout: timeout)
23+
}
24+
25+
/// Waits for the given `NSPredicate` to be true on `self` for the given `timeout` (default to
26+
/// 3 seconds)
27+
@discardableResult
28+
public func waitFor(predicate: NSPredicate, timeout: TimeInterval = 3.0) -> XCTWaiter.Result {
29+
XCTWaiter.wait(
30+
for: [ XCTNSPredicateExpectation(predicate: predicate, object: self) ],
2231
timeout: timeout
2332
)
24-
25-
return result == .completed
2633
}
2734
}

0 commit comments

Comments
 (0)