Skip to content

Commit 241d7cb

Browse files
test: use proper teardown for enrolment tests
1 parent 69c3a0c commit 241d7cb

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

e2eTest/FirebaseSwiftUIExample/FirebaseSwiftUIExampleUITests/MFAEnrolmentUITests.swift

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,24 @@
2222
import XCTest
2323

2424
final class MFAEnrollmentUITests: XCTestCase {
25+
var app: XCUIApplication!
26+
2527
override func setUpWithError() throws {
2628
continueAfterFailure = false
2729
}
30+
31+
override func tearDownWithError() throws {
32+
// Clean up: Terminate app
33+
if let app = app {
34+
app.terminate()
35+
}
36+
app = nil
37+
38+
// Small delay between tests to allow emulator to settle
39+
Thread.sleep(forTimeInterval: 0.5)
40+
41+
try super.tearDownWithError()
42+
}
2843

2944
// MARK: - MFA Management Navigation Tests
3045

@@ -35,7 +50,7 @@ final class MFAEnrollmentUITests: XCTestCase {
3550
// Create user in test runner before launching app
3651
try await createTestUser(email: email)
3752

38-
let app = createTestApp(mfaEnabled: true)
53+
app = createTestApp(mfaEnabled: true)
3954
app.launch()
4055

4156
// Sign in first to access MFA management
@@ -67,7 +82,7 @@ final class MFAEnrollmentUITests: XCTestCase {
6782
// Create user in test runner before launching app
6883
try await createTestUser(email: email)
6984

70-
let app = createTestApp(mfaEnabled: true)
85+
app = createTestApp(mfaEnabled: true)
7186
app.launch()
7287

7388
// Sign in and navigate to MFA management
@@ -102,7 +117,7 @@ final class MFAEnrollmentUITests: XCTestCase {
102117
// Create user in test runner before launching app
103118
try await createTestUser(email: email)
104119

105-
let app = createTestApp(mfaEnabled: true)
120+
app = createTestApp(mfaEnabled: true)
106121
app.launch()
107122

108123
// Navigate to MFA enrollment
@@ -131,7 +146,7 @@ final class MFAEnrollmentUITests: XCTestCase {
131146
// Create user in test runner before launching app
132147
try await createTestUser(email: email)
133148

134-
let app = createTestApp(mfaEnabled: true)
149+
app = createTestApp(mfaEnabled: true)
135150
app.launch()
136151

137152
// Navigate to MFA enrollment
@@ -168,7 +183,7 @@ final class MFAEnrollmentUITests: XCTestCase {
168183
let email = createEmail()
169184
try await createTestUser(email: email, verifyEmail: true)
170185

171-
let app = createTestApp(mfaEnabled: true)
186+
app = createTestApp(mfaEnabled: true)
172187
app.launch()
173188

174189
// 2) Sign in to reach SignedInView
@@ -210,7 +225,9 @@ final class MFAEnrollmentUITests: XCTestCase {
210225
// Enter phone number (without dial code)
211226
let phoneField = app.textFields["phone-number-field"]
212227
XCTAssertTrue(phoneField.waitForExistence(timeout: 10))
213-
let phoneNumberWithoutDialCode = "7444555666"
228+
// Generate unique phone number using timestamp to avoid conflicts between tests
229+
let uniqueId = Int(Date().timeIntervalSince1970 * 1000) % 1000000
230+
let phoneNumberWithoutDialCode = "7\(String(format: "%09d", uniqueId))"
214231
UIPasteboard.general.string = phoneNumberWithoutDialCode
215232
phoneField.tap()
216233
phoneField.press(forDuration: 1.2)
@@ -298,7 +315,7 @@ final class MFAEnrollmentUITests: XCTestCase {
298315
// Create user in test runner before launching app (with email verification)
299316
try await createTestUser(email: email, verifyEmail: true)
300317

301-
let app = createTestApp(mfaEnabled: true)
318+
app = createTestApp(mfaEnabled: true)
302319
app.launch()
303320

304321
// Navigate to MFA enrollment and select TOTP
@@ -357,7 +374,7 @@ final class MFAEnrollmentUITests: XCTestCase {
357374
// Create user in test runner before launching app
358375
try await createTestUser(email: email)
359376

360-
let app = createTestApp(mfaEnabled: true)
377+
app = createTestApp(mfaEnabled: true)
361378
app.launch()
362379

363380
// Navigate to MFA enrollment
@@ -377,7 +394,7 @@ final class MFAEnrollmentUITests: XCTestCase {
377394
// Create user in test runner before launching app
378395
try await createTestUser(email: email)
379396

380-
let app = createTestApp(mfaEnabled: true)
397+
app = createTestApp(mfaEnabled: true)
381398
app.launch()
382399

383400
// Navigate to MFA enrollment

0 commit comments

Comments
 (0)