Skip to content

Commit 442a358

Browse files
test: refactor wait for signed-in View
1 parent 79a47f1 commit 442a358

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExampleUITests/FirebaseSwiftUIExampleUITests.swift

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,20 @@ final class FirebaseSwiftUIExampleUITests: XCTestCase {
8282

8383
let signedInText = app.staticTexts["signed-in-text"]
8484

85-
let expectation = XCTNSPredicateExpectation(
86-
predicate: NSPredicate(format: "exists == true"),
87-
object: signedInText
88-
)
85+
let expectation = XCTestExpectation(description: "Wait for SignedInView to appear")
8986

87+
let checkInterval: TimeInterval = 1
9088
let maxWaitTime: TimeInterval = 30
91-
let result = XCTWaiter().wait(for: [expectation], timeout: maxWaitTime)
9289

93-
XCTAssertEqual(result, .completed, "SignedInView should be visible after login")
90+
Timer.scheduledTimer(withTimeInterval: checkInterval, repeats: true) { timer in
91+
if signedInText.exists {
92+
expectation.fulfill()
93+
timer.invalidate()
94+
}
95+
}
96+
97+
wait(for: [expectation], timeout: maxWaitTime)
98+
XCTAssertTrue(signedInText.exists, "SignedInView should be visible after login")
9499

95100
dismissAlert(app: app)
96101
// Check the Views are updated
@@ -184,14 +189,19 @@ final class FirebaseSwiftUIExampleUITests: XCTestCase {
184189

185190
let signedInText = app.staticTexts["signed-in-text"]
186191

187-
let expectation = XCTNSPredicateExpectation(
188-
predicate: NSPredicate(format: "exists == true"),
189-
object: signedInText
190-
)
192+
let expectation = XCTestExpectation(description: "Wait for SignedInView to appear")
191193

194+
let checkInterval: TimeInterval = 1
192195
let maxWaitTime: TimeInterval = 30
193-
let result = XCTWaiter().wait(for: [expectation], timeout: maxWaitTime)
194196

195-
XCTAssertEqual(result, .completed, "SignedInView should be visible after login")
197+
Timer.scheduledTimer(withTimeInterval: checkInterval, repeats: true) { timer in
198+
if signedInText.exists {
199+
expectation.fulfill()
200+
timer.invalidate()
201+
}
202+
}
203+
204+
wait(for: [expectation], timeout: maxWaitTime)
205+
XCTAssertTrue(signedInText.exists, "SignedInView should be visible after login")
196206
}
197207
}

0 commit comments

Comments
 (0)