// // UITestSupport.swift // OpenAppLockUITests // import XCTest extension XCUIApplication { /// Launches the app in UI-testing mode: in-memory storage, mocked Screen /// Time authorization, and no shield side effects. static func launchOpenAppLock( onboardingCompleted: Bool = true, seedScenario: String? = nil ) -> XCUIApplication { let app = XCUIApplication() var arguments = ["-ui-testing"] arguments.append(onboardingCompleted ? "-onboarding-completed" : "-onboarding-required") if let seedScenario { arguments.append("-seed-scenario=\(seedScenario)") } app.launchArguments = arguments app.launch() return app } } extension XCUIApplication { /// Finds an element by accessibility identifier regardless of how SwiftUI /// exposes it (Other, StaticText, Button, …). func element(_ identifier: String) -> XCUIElement { descendants(matching: .any).matching(identifier: identifier).firstMatch } } extension XCUIElement { /// Asserts the element appears within the timeout, then returns it. @discardableResult func waitToAppear( timeout: TimeInterval = 5, file: StaticString = #filePath, line: UInt = #line ) -> XCUIElement { XCTAssertTrue( waitForExistence(timeout: timeout), "Expected \(self) to exist within \(timeout)s", file: file, line: line ) return self } }