Skip to content

Commit eabe10c

Browse files
committed
Better Waiting
1 parent f1fad8c commit eabe10c

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

CodeEdit.xcodeproj/project.pbxproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3041,12 +3041,12 @@
30413041
6C96191F2C3F27E3009733CE /* CodeEditUITests */ = {
30423042
isa = PBXGroup;
30433043
children = (
3044-
6C510CB62D2E462D006EBE85 /* Extensions */,
30453044
6CFBA54A2C4E168A00E3A914 /* App.swift */,
3046-
6C9619232C3F2809009733CE /* ProjectPath.swift */,
3047-
6C9619212C3F27F1009733CE /* Query.swift */,
3045+
6C510CB62D2E462D006EBE85 /* Extensions */,
30483046
6C96191E2C3F27E3009733CE /* Features */,
30493047
6CFBA54E2C4E182100E3A914 /* Other Tests */,
3048+
6C9619232C3F2809009733CE /* ProjectPath.swift */,
3049+
6C9619212C3F27F1009733CE /* Query.swift */,
30503050
);
30513051
path = CodeEditUITests;
30523052
sourceTree = "<group>";

CodeEditUITests/Extensions/XCUITest+waitForNonExistence.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ extension XCUIElement {
1313
/// Waits the specified amount of time for the element’s `exists` property to become `false`.
1414
/// - Parameter timeout: The amount of time to wait.
1515
/// - Returns: `false` if the timeout expires without the element coming out of existence.
16-
///
1716
func waitForNonExistence(timeout: TimeInterval) -> Bool {
18-
let timeStart = Date().timeIntervalSince1970
19-
20-
while Date().timeIntervalSince1970 <= (timeStart + timeout) {
21-
if !exists { return true }
17+
let predicate = NSPredicate(format: "exists == false")
18+
switch XCTWaiter.wait(for: [XCTNSPredicateExpectation(predicate: predicate, object: self)], timeout: timeout) {
19+
case .completed:
20+
return true
21+
default:
22+
return false
2223
}
23-
24-
return false
2524
}
2625
}

CodeEditUITests/Features/ActivityViewer/Tasks/TasksMenuUITests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,22 @@ final class ActivityViewerTasksMenuTests: XCTestCase {
4545
let taskDropdown = viewer.buttons["Active Task"]
4646
taskDropdown.click()
4747
let popover = app.popovers.firstMatch
48-
XCTAssertTrue(popover.waitForExistence(timeout: 2.0), "Popover did not appear on click")
48+
XCTAssertTrue(popover.exists, "Popover did not appear on click")
4949

5050
let addTaskListOption = popover.buttons["Add Task..."]
5151
XCTAssertTrue(addTaskListOption.exists, "No add task option in dropdown")
5252
addTaskListOption.click()
5353

5454
let workspaceSettingsWindow = window.sheets["Workspace Settings"]
55-
XCTAssertTrue(workspaceSettingsWindow.waitForExistence(timeout: 2.0), "Workspace settings did not appear")
55+
XCTAssertTrue(workspaceSettingsWindow.waitForExistence(timeout: 1.0), "Workspace settings did not appear")
5656

5757
let addTaskButton = workspaceSettingsWindow.buttons["Add Task..."]
5858
XCTAssertTrue(addTaskButton.exists, "No add task button")
5959
addTaskButton.click()
6060

6161
// Enter in task information
6262
let newSheet = workspaceSettingsWindow.sheets.firstMatch
63-
XCTAssertTrue(newSheet.waitForExistence(timeout: 2.0), "New task sheet did not appear")
63+
XCTAssertTrue(newSheet.waitForExistence(timeout: 1.0), "New task sheet did not appear")
6464
let taskName = newSheet.textFields["Task Name"]
6565
XCTAssertTrue(taskName.exists)
6666
taskName.click()
@@ -79,7 +79,7 @@ final class ActivityViewerTasksMenuTests: XCTestCase {
7979

8080
workspaceSettingsWindow.buttons["Done"].click()
8181
XCTAssertFalse(
82-
workspaceSettingsWindow.waitForNonExistence(timeout: 2.0),
82+
workspaceSettingsWindow.waitForNonExistence(timeout: 1.0),
8383
"Workspace Settings should have dismissed"
8484
)
8585

0 commit comments

Comments
 (0)