diff --git a/PediFoodsUITests/AuthenticatedProfileNavigationTests.swift b/PediFoodsUITests/AuthenticatedProfileNavigationTests.swift index 631c48b..7079ee5 100644 --- a/PediFoodsUITests/AuthenticatedProfileNavigationTests.swift +++ b/PediFoodsUITests/AuthenticatedProfileNavigationTests.swift @@ -13,9 +13,13 @@ final class AuthenticatedProfileNavigationTests: XCTestCase { continueAfterFailure = false } - override func tearDownWithError() throws { - XCUIApplication().logoutIfAuthenticated() - } + // No per-test logout: the standing QA account's Keychain session is + // meant to persist across authenticated-flow tests, so only the first + // one in a suite run pays for a real OTP round trip. Tests that need a + // guaranteed logged-out state (HomeGuestFlowTests, + // ProfileLoggedOutFlowTests) force it themselves in their own setUp + // instead of relying on every authenticated class to log out after + // itself - see decisions/2026-09-11-ui-test-shared-login-session.md. func testOrdersScreenReachableAndLoadsRealData() throws { let app = XCUIApplication() diff --git a/PediFoodsUITests/AuthenticatedSessionFlowTests.swift b/PediFoodsUITests/AuthenticatedSessionFlowTests.swift index 461d007..e3d3c3d 100644 --- a/PediFoodsUITests/AuthenticatedSessionFlowTests.swift +++ b/PediFoodsUITests/AuthenticatedSessionFlowTests.swift @@ -2,17 +2,14 @@ import XCTest /// Covers a real, authenticated session with the standing QA account (see /// TestFixtures.swift / decisions/2026-08-06-ui-test-account-and-app-attest-bypass.md). -/// Logs out in tearDown so guest-only tests elsewhere in the same run don't -/// inherit an authenticated Keychain session. +/// No per-test logout - the Keychain session is meant to persist across +/// authenticated-flow tests in the same run; see +/// decisions/2026-09-11-ui-test-shared-login-session.md. final class AuthenticatedSessionFlowTests: XCTestCase { override func setUpWithError() throws { continueAfterFailure = false } - override func tearDownWithError() throws { - XCUIApplication().logoutIfAuthenticated() - } - func testLoginReachesAuthenticatedProfile() throws { let app = XCUIApplication() app.launch() diff --git a/PediFoodsUITests/CartCheckoutFlowTests.swift b/PediFoodsUITests/CartCheckoutFlowTests.swift index 0a1fae2..77efe88 100644 --- a/PediFoodsUITests/CartCheckoutFlowTests.swift +++ b/PediFoodsUITests/CartCheckoutFlowTests.swift @@ -10,9 +10,7 @@ final class CartCheckoutFlowTests: XCTestCase { continueAfterFailure = false } - override func tearDownWithError() throws { - XCUIApplication().logoutIfAuthenticated() - } + // No per-test logout - see decisions/2026-09-11-ui-test-shared-login-session.md. func testAddProductToCartAndReachCheckout() throws { let app = XCUIApplication() diff --git a/PediFoodsUITests/HomeFiltersFlowTests.swift b/PediFoodsUITests/HomeFiltersFlowTests.swift index b936d6e..bb6d67b 100644 --- a/PediFoodsUITests/HomeFiltersFlowTests.swift +++ b/PediFoodsUITests/HomeFiltersFlowTests.swift @@ -20,9 +20,7 @@ final class HomeFiltersFlowTests: XCTestCase { continueAfterFailure = false } - override func tearDownWithError() throws { - XCUIApplication().logoutIfAuthenticated() - } + // No per-test logout - see decisions/2026-09-11-ui-test-shared-login-session.md. func testFiltersSheetSelectionsAndApply() throws { let app = XCUIApplication() diff --git a/PediFoodsUITests/HomeGuestFlowTests.swift b/PediFoodsUITests/HomeGuestFlowTests.swift index 74a6a09..34a61be 100644 --- a/PediFoodsUITests/HomeGuestFlowTests.swift +++ b/PediFoodsUITests/HomeGuestFlowTests.swift @@ -10,9 +10,19 @@ final class HomeGuestFlowTests: XCTestCase { continueAfterFailure = false } - func testHomeRendersSearchAndGreeting() throws { + /// Authenticated-flow tests no longer log out after themselves (see + /// decisions/2026-09-11-ui-test-shared-login-session.md), so guest + /// tests must force a clean logged-out state themselves right after + /// launch, rather than assume one. + private func launchGuestApp() -> XCUIApplication { let app = XCUIApplication() app.launch() + app.logoutIfAuthenticated() + return app + } + + func testHomeRendersSearchAndGreeting() throws { + let app = launchGuestApp() XCTAssertTrue(app.reachGuestHome(), "Never reached Home's search field") XCTAssertTrue(app.staticTexts["ENTREGAR EM:"].exists) @@ -21,8 +31,7 @@ final class HomeGuestFlowTests: XCTestCase { } func testHomeShowsDefaultCategoryChip() throws { - let app = XCUIApplication() - app.launch() + let app = launchGuestApp() XCTAssertTrue(app.reachGuestHome()) XCTAssertTrue(app.staticTexts["Categories"].exists) @@ -30,8 +39,7 @@ final class HomeGuestFlowTests: XCTestCase { } func testHomeShowsGuestLocationPromptWhenNoLocationChosen() throws { - let app = XCUIApplication() - app.launch() + let app = launchGuestApp() XCTAssertTrue(app.reachGuestHome()) // No guest state/city selected -> Home's own inline message, not @@ -40,8 +48,7 @@ final class HomeGuestFlowTests: XCTestCase { } func testTappingAddressChipReopensLocationPicker() throws { - let app = XCUIApplication() - app.launch() + let app = launchGuestApp() XCTAssertTrue(app.reachGuestHome()) // The "ENTREGAR EM:" address button re-opens the same address diff --git a/PediFoodsUITests/OrderDetailsFlowTests.swift b/PediFoodsUITests/OrderDetailsFlowTests.swift index 74f8512..5a3a987 100644 --- a/PediFoodsUITests/OrderDetailsFlowTests.swift +++ b/PediFoodsUITests/OrderDetailsFlowTests.swift @@ -9,9 +9,7 @@ final class OrderDetailsFlowTests: XCTestCase { continueAfterFailure = false } - override func tearDownWithError() throws { - XCUIApplication().logoutIfAuthenticated() - } + // No per-test logout - see decisions/2026-09-11-ui-test-shared-login-session.md. func testOrderDetailsReachableFromOrdersList() throws { let app = XCUIApplication() diff --git a/PediFoodsUITests/ProfileLoggedOutFlowTests.swift b/PediFoodsUITests/ProfileLoggedOutFlowTests.swift index 5a547e3..068bfa6 100644 --- a/PediFoodsUITests/ProfileLoggedOutFlowTests.swift +++ b/PediFoodsUITests/ProfileLoggedOutFlowTests.swift @@ -7,9 +7,19 @@ final class ProfileLoggedOutFlowTests: XCTestCase { continueAfterFailure = false } - func testLoggedOutProfileShowsLoginPrompt() throws { + /// Authenticated-flow tests no longer log out after themselves (see + /// decisions/2026-09-11-ui-test-shared-login-session.md), so + /// logged-out tests must force a clean state themselves right after + /// launch, rather than assume one. + private func launchLoggedOutApp() -> XCUIApplication { let app = XCUIApplication() app.launch() + app.logoutIfAuthenticated() + return app + } + + func testLoggedOutProfileShowsLoginPrompt() throws { + let app = launchLoggedOutApp() XCTAssertTrue(app.reachLoggedOutProfile(), "Never reached the logged-out profile screen") XCTAssertTrue(app.staticTexts["Entre na sua conta"].exists) @@ -22,8 +32,7 @@ final class ProfileLoggedOutFlowTests: XCTestCase { /// a working way back out (its `LCENavigationView` back button, which /// sets `root = .main`). func testAuthIntroScreenShowsChoicesAndCanGoBack() throws { - let app = XCUIApplication() - app.launch() + let app = launchLoggedOutApp() XCTAssertTrue(app.reachLoggedOutProfile()) app.buttons["Entrar ou Cadastrar"].tap() @@ -45,8 +54,7 @@ final class ProfileLoggedOutFlowTests: XCTestCase { /// app's standard `AppBackButtonIcon` via `LCENavigationView`, not the /// oversized iOS 26 system glass back button. func testPushedAuthScreensUseAppBackButton() throws { - let app = XCUIApplication() - app.launch() + let app = launchLoggedOutApp() XCTAssertTrue(app.reachLoggedOutProfile()) app.buttons["Entrar ou Cadastrar"].tap() diff --git a/PediFoodsUITests/SavedCardsFlowTests.swift b/PediFoodsUITests/SavedCardsFlowTests.swift index 3dd2b0f..a1f3949 100644 --- a/PediFoodsUITests/SavedCardsFlowTests.swift +++ b/PediFoodsUITests/SavedCardsFlowTests.swift @@ -9,9 +9,7 @@ final class SavedCardsFlowTests: XCTestCase { continueAfterFailure = false } - override func tearDownWithError() throws { - XCUIApplication().logoutIfAuthenticated() - } + // No per-test logout - see decisions/2026-09-11-ui-test-shared-login-session.md. func testAddCardFormReachableFromSavedCards() throws { let app = XCUIApplication() diff --git a/PediFoodsUITests/UserProfileFlowTests.swift b/PediFoodsUITests/UserProfileFlowTests.swift index 126afa6..8ad3eaa 100644 --- a/PediFoodsUITests/UserProfileFlowTests.swift +++ b/PediFoodsUITests/UserProfileFlowTests.swift @@ -7,9 +7,7 @@ final class UserProfileFlowTests: XCTestCase { continueAfterFailure = false } - override func tearDownWithError() throws { - XCUIApplication().logoutIfAuthenticated() - } + // No per-test logout - see decisions/2026-09-11-ui-test-shared-login-session.md. func testUserProfileReachableFromProfileHeader() throws { let app = XCUIApplication()