Files
suixinkan_ios_new/suixinkanUITests/Support/SuixinkanUIApplication.swift
汉秋 8997d1ba1c 集成 MJRefresh 并重构主 TabBar 为系统 TabView 样式。
新增 SwiftUI 桥接层与单元测试,更新 Tab 图标资源命名和多倍图,同步调整 UI Test 的 Tab/扫码定位逻辑。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-29 10:22:53 +08:00

99 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()
if waitForLoading {
waitForGlobalLoadingToDisappear()
}
return self
}
/// 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)
}
/// 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))
}
}
}