为 TabBar 和扫码页补充 accessibilityIdentifier,并在模拟器/UI Test 中禁用真实相机采集。
预初始化各 Tab 路由容器,修正 iOS 17 ContentUnavailableView 调用,提升自定义 TabBar 与扫码流程的 UI Test 稳定性。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@ -63,7 +63,7 @@ final class OrdersFlowUITests: AuthenticatedUITestCase {
|
||||
func testScannerCanOpenAndClose() {
|
||||
TabBarNavigator.select(.orders, app: app)
|
||||
|
||||
let scanButton = app.application.buttons["扫码核销"]
|
||||
let scanButton = app.application.buttons["main.scan"]
|
||||
XCTAssertTrue(scanButton.waitForExistence(timeout: 6))
|
||||
scanButton.tap()
|
||||
|
||||
|
||||
@ -11,6 +11,7 @@ import XCTest
|
||||
final class SuixinkanApp {
|
||||
let application: XCUIApplication
|
||||
private let resetState: Bool
|
||||
private var hasLaunched = false
|
||||
|
||||
/// 创建并配置 UI Test 启动参数的应用实例。
|
||||
init(
|
||||
@ -31,10 +32,15 @@ final class SuixinkanApp {
|
||||
/// 启动 App 并等待首屏稳定。
|
||||
@discardableResult
|
||||
func launch(waitForLoading: Bool = true) -> Self {
|
||||
if application.state == .runningForeground {
|
||||
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 {
|
||||
@ -72,12 +78,10 @@ final class SuixinkanApp {
|
||||
|
||||
/// 判断主 Tab 是否已出现。
|
||||
var isOnMainTabs: Bool {
|
||||
TabBarNavigator.Tab.allCases.contains { tab in
|
||||
let button = application.buttons.matching(
|
||||
NSPredicate(format: "label == %@", tab.rawValue)
|
||||
).firstMatch
|
||||
return button.waitForExistence(timeout: 1)
|
||||
}
|
||||
application.buttons[TabBarNavigator.Tab.home.identifier].exists
|
||||
|| application.buttons[TabBarNavigator.Tab.orders.identifier].exists
|
||||
|| application.buttons[TabBarNavigator.Tab.statistics.identifier].exists
|
||||
|| application.buttons[TabBarNavigator.Tab.profile.identifier].exists
|
||||
}
|
||||
|
||||
/// 等待冷启动后进入登录页或主 Tab。
|
||||
|
||||
@ -14,6 +14,19 @@ enum TabBarNavigator {
|
||||
case orders = "订单"
|
||||
case statistics = "数据"
|
||||
case profile = "我的"
|
||||
|
||||
var identifier: String {
|
||||
switch self {
|
||||
case .home:
|
||||
return "main.tab.home"
|
||||
case .orders:
|
||||
return "main.tab.orders"
|
||||
case .statistics:
|
||||
return "main.tab.statistics"
|
||||
case .profile:
|
||||
return "main.tab.profile"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 切换到指定 Tab 并等待页面稳定。
|
||||
@ -26,6 +39,13 @@ enum TabBarNavigator {
|
||||
|
||||
/// 在底部自定义 TabBar 中定位唯一可点击的 Tab 按钮。
|
||||
private static func bottomTabButton(named title: String, in app: SuixinkanApp) -> XCUIElement {
|
||||
if let tab = Tab(rawValue: title) {
|
||||
let identifiedButton = app.application.buttons[tab.identifier]
|
||||
if identifiedButton.exists {
|
||||
return identifiedButton
|
||||
}
|
||||
}
|
||||
|
||||
let candidates = app.application.buttons.matching(NSPredicate(format: "label == %@", title))
|
||||
let screenHeight = app.application.windows.element(boundBy: 0).frame.height
|
||||
var bestMatch: XCUIElement?
|
||||
|
||||
Reference in New Issue
Block a user