Skip to content

Commit d97238b

Browse files
test: remove Timer from UI tests
1 parent 54bb93e commit d97238b

File tree

1 file changed

+10
-33
lines changed

1 file changed

+10
-33
lines changed

samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExampleUITests/FirebaseSwiftUIExampleUITests.swift

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,12 @@ final class FirebaseSwiftUIExampleUITests: XCTestCase {
7474
XCTAssertTrue(signInButton.exists, "Sign-In button should exist")
7575
signInButton.tap()
7676

77+
// Wait for authentication to complete and signed-in view to appear
7778
let signedInText = app.staticTexts["signed-in-text"]
78-
let expectation = XCTestExpectation(description: "Wait for SignedInView to appear")
79-
80-
let checkInterval: TimeInterval = 1
81-
let maxWaitTime: TimeInterval = 30
82-
83-
Timer.scheduledTimer(withTimeInterval: checkInterval, repeats: true) { timer in
84-
DispatchQueue.main.async {
85-
if signedInText.exists {
86-
expectation.fulfill()
87-
timer.invalidate()
88-
}
89-
}
90-
}
91-
92-
wait(for: [expectation], timeout: maxWaitTime)
93-
XCTAssertTrue(signedInText.exists, "SignedInView should be visible after login")
79+
XCTAssertTrue(
80+
signedInText.waitForExistence(timeout: 30),
81+
"SignedInView should be visible after login"
82+
)
9483

9584
dismissAlert(app: app)
9685
// Check the Views are updated
@@ -190,23 +179,11 @@ final class FirebaseSwiftUIExampleUITests: XCTestCase {
190179
XCTAssertTrue(signUpButton.exists, "Sign-Up button should exist")
191180
signUpButton.tap()
192181

182+
// Wait for user creation and signed-in view to appear
193183
let signedInText = app.staticTexts["signed-in-text"]
194-
195-
let expectation = XCTestExpectation(description: "Wait for SignedInView to appear")
196-
197-
let checkInterval: TimeInterval = 1
198-
let maxWaitTime: TimeInterval = 30
199-
200-
Timer.scheduledTimer(withTimeInterval: checkInterval, repeats: true) { timer in
201-
DispatchQueue.main.async {
202-
if signedInText.exists {
203-
expectation.fulfill()
204-
timer.invalidate()
205-
}
206-
}
207-
}
208-
209-
wait(for: [expectation], timeout: maxWaitTime)
210-
XCTAssertTrue(signedInText.exists, "SignedInView should be visible after login")
184+
XCTAssertTrue(
185+
signedInText.waitForExistence(timeout: 30),
186+
"SignedInView should be visible after user creation"
187+
)
211188
}
212189
}

0 commit comments

Comments
 (0)