Files
suixinkan_ios_new/suixinkanUITests/Support/SuixinkanUIApplication.swift
汉秋 258c438f9a 优化冷启动流程:Launch Screen 对齐 Splash,仅阻塞 rolePermissions。
移除 SplashCoordinator,bootstrap 期间用 SplashView 覆盖避免空白闪屏,其余账号数据改为后台补充刷新。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-30 09:56:49 +08:00

100 lines
3.1 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// SuixinkanUIApplication.swift
// suixinkanUITests
//
// Created by Codex on 2026/6/26.
//
import XCTest
/// XCUIApplication Loading
final class SuixinkanApp {
let application: XCUIApplication
private let resetState: Bool
private var hasLaunched = false
/// UI Test
init(
resetState: Bool = false,
openMenuTitle: String? = nil,
openProfileRoute: String? = nil
) {
self.resetState = resetState
application = XCUIApplication()
UITestLaunchConfiguration.apply(
to: application,
resetState: resetState,
openMenu: openMenuTitle,
openProfile: openProfileRoute
)
}
/// App
@discardableResult
func launch(waitForLoading: Bool = true) -> Self {
if hasLaunched, application.state == .runningForeground {
application.activate()
} else {
if application.state != .notRunning {
application.terminate()
Thread.sleep(forTimeInterval: 0.5)
}
application.launch()
hasLaunched = true
}
dismissSystemAlertsIfNeeded()
waitForInitialScreen()
if waitForLoading {
waitForGlobalLoadingToDisappear()
}
return self
}
/// Tab
func waitForInitialScreen(timeout: TimeInterval = 45) {
if application.staticTexts["login.title"].waitForExistence(timeout: 2) {
return
}
let deadline = Date().addingTimeInterval(timeout)
while Date() < deadline {
if isOnMainTabs {
return
}
RunLoop.current.run(until: Date().addingTimeInterval(0.2))
}
}
/// Loading
func waitForGlobalLoadingToDisappear(timeout: TimeInterval = 45) {
let loading = application.staticTexts["加载中"]
guard loading.waitForExistence(timeout: 2) else { return }
let predicate = NSPredicate(format: "exists == false")
let expectation = XCTNSPredicateExpectation(predicate: predicate, object: loading)
_ = XCTWaiter.wait(for: [expectation], timeout: timeout)
}
/// 便
func dismissSystemAlertsIfNeeded() {
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
let allowButtons = ["允许", "", "使用App时允许", "Allow", "Allow While Using App", "OK"]
for title in allowButtons {
let button = springboard.buttons[title]
if button.waitForExistence(timeout: 1) {
button.tap()
}
}
}
///
var isOnLoginScreen: Bool {
application.staticTexts["login.title"].exists
}
/// Tab
var isOnMainTabs: Bool {
TabBarNavigator.isVisible(in: self)
}
}