Files
suixinkan_ios_new/suixinkanUITests/Support/SuixinkanUIApplication.swift
汉秋 0c01ee26c3 新增完整 UI Test 回归套件,并完善启动隔离逻辑。
按模块拆分 XCUITest 用例与 Support 基础设施,UI Test 运行时跳过推送与排队 WebSocket,并将 Podfile 最低版本对齐 iOS 16。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-26 10:45:00 +08:00

79 lines
2.6 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
/// UI Test
init(resetState: Bool = false) {
self.resetState = resetState
application = XCUIApplication()
UITestLaunchConfiguration.apply(to: application, resetState: resetState)
}
/// App
@discardableResult
func launch(waitForLoading: Bool = true) -> Self {
if application.state == .runningForeground {
application.activate()
} else {
application.launch()
}
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 {
application.buttons["首页"].waitForExistence(timeout: 1)
|| application.buttons["我的"].waitForExistence(timeout: 1)
}
/// Tab
func waitForInitialScreen(timeout: TimeInterval = 45) {
if application.staticTexts["login.title"].waitForExistence(timeout: 2) {
return
}
_ = application.buttons["首页"].waitForExistence(timeout: timeout)
|| application.buttons["我的"].waitForExistence(timeout: 2)
}
}