@@ -23,12 +23,6 @@ import FirebaseAuth
2323import FirebaseCore
2424import XCTest
2525
26- func createEmail( ) -> String {
27- let before = UUID ( ) . uuidString. prefix ( 8 )
28- let after = UUID ( ) . uuidString. prefix ( 6 )
29- return " \( before) @ \( after) .com "
30- }
31-
3226func dismissAlert( app: XCUIApplication ) {
3327 if app. scrollViews. otherElements. buttons [ " Not Now " ] . waitForExistence ( timeout: 2 ) {
3428 app. scrollViews. otherElements. buttons [ " Not Now " ] . tap ( )
@@ -58,7 +52,7 @@ final class FirebaseSwiftUIExampleUITests: XCTestCase {
5852 }
5953
6054 @MainActor
61- func testSignInDisplaysSignedInView( ) async throws {
55+ func testSignInDisplaysSignedInView( ) throws {
6256 let app = XCUIApplication ( )
6357 let email = createEmail ( )
6458 app. launchArguments. append ( " --auth-emulator " )
@@ -81,10 +75,22 @@ final class FirebaseSwiftUIExampleUITests: XCTestCase {
8175 signInButton. tap ( )
8276
8377 let signedInText = app. staticTexts [ " signed-in-text " ]
84- XCTAssertTrue (
85- signedInText. waitForExistence ( timeout: 10 ) ,
86- " SignedInView should be visible after login "
87- )
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 " )
8894
8995 dismissAlert ( app: app)
9096 // Check the Views are updated
@@ -149,6 +155,12 @@ final class FirebaseSwiftUIExampleUITests: XCTestCase {
149155 app. launchArguments. append ( " --auth-emulator " )
150156 app. launch ( )
151157
158+ // Check the Views are updated
159+ let signOutButton = app. buttons [ " sign-out-button " ]
160+ if signOutButton. exists {
161+ signOutButton. tap ( )
162+ }
163+
152164 let switchFlowButton = app. buttons [ " switch-auth-flow " ]
153165 switchFlowButton. tap ( )
154166
@@ -172,14 +184,29 @@ final class FirebaseSwiftUIExampleUITests: XCTestCase {
172184 confirmPasswordField. press ( forDuration: 1.2 )
173185 app. menuItems [ " Paste " ] . tap ( )
174186
175- let signInButton = app. buttons [ " sign-in-button " ]
176- XCTAssertTrue ( signInButton. exists, " Sign-In button should exist " )
177- signInButton. tap ( )
187+ // Create the user (sign up)
188+ let signUpButton = app
189+ . buttons [ " sign-in-button " ] // This button changes context after switch-auth-flow
190+ XCTAssertTrue ( signUpButton. exists, " Sign-Up button should exist " )
191+ signUpButton. tap ( )
178192
179193 let signedInText = app. staticTexts [ " signed-in-text " ]
180- XCTAssertTrue (
181- signedInText. waitForExistence ( timeout: 20 ) ,
182- " SignedInView should be visible after login "
183- )
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 " )
184211 }
185212}
0 commit comments