Stabilize iOS UI test foundation and fix flaky suites
This commit is contained in:
@@ -10,43 +10,43 @@ import XCTest
|
||||
struct TabBarScreen {
|
||||
let app: XCUIApplication
|
||||
|
||||
// MARK: - Tab Buttons (using localized labels)
|
||||
// MARK: - Tab Buttons
|
||||
|
||||
var dayTab: XCUIElement { app.tabBars.buttons["Day"] }
|
||||
var monthTab: XCUIElement { app.tabBars.buttons["Month"] }
|
||||
var yearTab: XCUIElement { app.tabBars.buttons["Year"] }
|
||||
var insightsTab: XCUIElement { app.tabBars.buttons["Insights"] }
|
||||
var settingsTab: XCUIElement { app.tabBars.buttons["Settings"] }
|
||||
var dayTab: XCUIElement { tab(identifier: UITestID.Tab.day, labels: ["Day", "Main"]) }
|
||||
var monthTab: XCUIElement { tab(identifier: UITestID.Tab.month, labels: ["Month"]) }
|
||||
var yearTab: XCUIElement { tab(identifier: UITestID.Tab.year, labels: ["Year", "Filter"]) }
|
||||
var insightsTab: XCUIElement { tab(identifier: UITestID.Tab.insights, labels: ["Insights"]) }
|
||||
var settingsTab: XCUIElement { tab(identifier: UITestID.Tab.settings, labels: ["Settings"]) }
|
||||
|
||||
// MARK: - Actions
|
||||
|
||||
@discardableResult
|
||||
func tapDay() -> DayScreen {
|
||||
tapTab(dayTab)
|
||||
app.tapTab(identifier: UITestID.Tab.day, labels: ["Day", "Main"])
|
||||
return DayScreen(app: app)
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
func tapMonth() -> TabBarScreen {
|
||||
tapTab(monthTab)
|
||||
app.tapTab(identifier: UITestID.Tab.month, labels: ["Month"])
|
||||
return self
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
func tapYear() -> TabBarScreen {
|
||||
tapTab(yearTab)
|
||||
app.tapTab(identifier: UITestID.Tab.year, labels: ["Year", "Filter"])
|
||||
return self
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
func tapInsights() -> TabBarScreen {
|
||||
tapTab(insightsTab)
|
||||
app.tapTab(identifier: UITestID.Tab.insights, labels: ["Insights"])
|
||||
return self
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
func tapSettings() -> SettingsScreen {
|
||||
tapTab(settingsTab)
|
||||
app.tapTab(identifier: UITestID.Tab.settings, labels: ["Settings"])
|
||||
return SettingsScreen(app: app)
|
||||
}
|
||||
|
||||
@@ -57,15 +57,27 @@ struct TabBarScreen {
|
||||
}
|
||||
|
||||
func assertTabBarVisible() {
|
||||
XCTAssertTrue(dayTab.waitForExistence(timeout: 5), "Tab bar should be visible")
|
||||
let visible = dayTab.waitForExistence(timeout: 5) ||
|
||||
monthTab.waitForExistence(timeout: 1) ||
|
||||
settingsTab.waitForExistence(timeout: 1)
|
||||
XCTAssertTrue(visible, "Tab bar should be visible")
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
// MARK: - Element Resolution
|
||||
|
||||
/// Tap a tab bar button. Uses coordinate tap to avoid iOS 26 Liquid Glass
|
||||
/// overlay elements reporting buttons as not hittable.
|
||||
private func tapTab(_ tab: XCUIElement) {
|
||||
_ = tab.waitForExistence(timeout: 5)
|
||||
tab.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
|
||||
private func tab(identifier: String, labels: [String]) -> XCUIElement {
|
||||
let idMatch = app.tabBars.buttons[identifier]
|
||||
if idMatch.exists {
|
||||
return idMatch
|
||||
}
|
||||
|
||||
for label in labels {
|
||||
let match = app.tabBars.buttons[label]
|
||||
if match.exists {
|
||||
return match
|
||||
}
|
||||
}
|
||||
|
||||
return app.tabBars.buttons[labels.first ?? identifier]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user