Fix accessibility IDs and settings scroll for remaining test failures
- Added month_grid accessibility ID to MonthView ScrollView - Added year_heatmap accessibility ID to YearView ScrollView - Fixed DayScreen.assertVisible() to accept entry rows OR mood header - Fixed DataPersistenceTests for in-memory storage (fixture re-seeds) - Fixed AppLaunchTests to use week_of_moods fixture (empty has no grid) - Fixed SettingsScreen segmented control tap with multi-strategy fallback - Improved settings scroll with coordinate-based swipe for deep elements - OnboardingScreen swipeToNext uses slow velocity for paged TabView Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -38,45 +38,69 @@ struct SettingsScreen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func tapSegment(identifier: String, fallbackLabel: String, file: StaticString, line: UInt) {
|
private func tapSegment(identifier: String, fallbackLabel: String, file: StaticString, line: UInt) {
|
||||||
// Try accessibility ID on the descendant element (SwiftUI puts IDs on Text inside Picker)
|
// On iOS 26, segmented controls may expose buttons by label or by ID.
|
||||||
let byID = app.element(identifier)
|
// Try multiple strategies in order of reliability.
|
||||||
if byID.waitForExistence(timeout: defaultTimeout) {
|
|
||||||
if byID.isHittable {
|
// Strategy 1: Segmented control button by label (most reliable)
|
||||||
byID.tap()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// Element exists but not hittable — try coordinate tap
|
|
||||||
byID.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// Fallback: segmented control button by label
|
|
||||||
let segButton = app.segmentedControls.buttons[fallbackLabel]
|
let segButton = app.segmentedControls.buttons[fallbackLabel]
|
||||||
if segButton.waitForExistence(timeout: defaultTimeout) {
|
if segButton.waitForExistence(timeout: defaultTimeout) && segButton.isHittable {
|
||||||
segButton.tap()
|
segButton.tap()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Last fallback: find buttons matching label that are NOT in tab bar
|
|
||||||
let allButtons = app.buttons.matching(NSPredicate(format: "label == %@", fallbackLabel)).allElementsBoundByIndex
|
// Strategy 2: Find a non-tab-bar button with matching label
|
||||||
let tabBarButton = app.tabBars.buttons[fallbackLabel]
|
let tabBarButton = app.tabBars.buttons[fallbackLabel]
|
||||||
|
let allButtons = app.buttons.matching(NSPredicate(format: "label == %@", fallbackLabel)).allElementsBoundByIndex
|
||||||
for button in allButtons {
|
for button in allButtons {
|
||||||
if button.frame != tabBarButton.frame && button.isHittable {
|
if button.isHittable && button.frame != tabBarButton.frame {
|
||||||
button.tap()
|
button.tap()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Strategy 3: Accessibility ID with coordinate tap fallback
|
||||||
|
let byID = app.element(identifier)
|
||||||
|
if byID.waitForExistence(timeout: defaultTimeout) {
|
||||||
|
byID.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
XCTFail("Could not find segment '\(fallbackLabel)' by ID or label", file: file, line: line)
|
XCTFail("Could not find segment '\(fallbackLabel)' by ID or label", file: file, line: line)
|
||||||
}
|
}
|
||||||
|
|
||||||
func tapClearData(file: StaticString = #filePath, line: UInt = #line) {
|
func tapClearData(file: StaticString = #filePath, line: UInt = #line) {
|
||||||
clearDataButton.scrollIntoView(in: app, direction: .up, maxSwipes: 5, file: file, line: line)
|
scrollToSettingsElement(clearDataButton, maxSwipes: 20, file: file, line: line)
|
||||||
clearDataButton.forceTap(file: file, line: line)
|
clearDataButton.forceTap(file: file, line: line)
|
||||||
}
|
}
|
||||||
|
|
||||||
func tapAnalyticsToggle(file: StaticString = #filePath, line: UInt = #line) {
|
func tapAnalyticsToggle(file: StaticString = #filePath, line: UInt = #line) {
|
||||||
analyticsToggle.scrollIntoView(in: app, direction: .up, maxSwipes: 5, file: file, line: line)
|
scrollToSettingsElement(analyticsToggle, maxSwipes: 15, file: file, line: line)
|
||||||
analyticsToggle.forceTap(file: file, line: line)
|
analyticsToggle.forceTap(file: file, line: line)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Scroll within the settings content to find a deeply nested element.
|
||||||
|
/// Uses aggressive swipes on the main app surface since the ScrollView
|
||||||
|
/// hierarchy varies by iOS version.
|
||||||
|
private func scrollToSettingsElement(
|
||||||
|
_ element: XCUIElement,
|
||||||
|
maxSwipes: Int,
|
||||||
|
file: StaticString,
|
||||||
|
line: UInt
|
||||||
|
) {
|
||||||
|
if element.exists && element.isHittable { return }
|
||||||
|
|
||||||
|
for _ in 0..<maxSwipes {
|
||||||
|
// Swipe up from center to scroll the settings content
|
||||||
|
let start = app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.8))
|
||||||
|
let end = app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.2))
|
||||||
|
start.press(forDuration: 0.05, thenDragTo: end)
|
||||||
|
|
||||||
|
if element.exists && element.isHittable { return }
|
||||||
|
}
|
||||||
|
|
||||||
|
XCTFail("Could not scroll to settings element after \(maxSwipes) swipes: \(element)", file: file, line: line)
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Assertions
|
// MARK: - Assertions
|
||||||
|
|
||||||
@discardableResult
|
@discardableResult
|
||||||
|
|||||||
@@ -23,9 +23,7 @@ final class SettingsActionTests: BaseUITestCase {
|
|||||||
settingsScreen.assertVisible()
|
settingsScreen.assertVisible()
|
||||||
settingsScreen.tapSettingsTab()
|
settingsScreen.tapSettingsTab()
|
||||||
|
|
||||||
// Scroll to and tap Clear All Data
|
// Scroll to and tap Clear All Data (tapClearData handles scrolling)
|
||||||
settingsScreen.clearDataButton
|
|
||||||
.scrollIntoView(in: app.scrollViews.firstMatch, direction: .up)
|
|
||||||
settingsScreen.tapClearData()
|
settingsScreen.tapClearData()
|
||||||
|
|
||||||
// Navigate back to Day tab
|
// Navigate back to Day tab
|
||||||
@@ -52,9 +50,7 @@ final class SettingsActionTests: BaseUITestCase {
|
|||||||
settingsScreen.assertVisible()
|
settingsScreen.assertVisible()
|
||||||
settingsScreen.tapSettingsTab()
|
settingsScreen.tapSettingsTab()
|
||||||
|
|
||||||
// Scroll to analytics toggle and tap it
|
// Scroll to analytics toggle and tap it (tapAnalyticsToggle handles scrolling)
|
||||||
settingsScreen.analyticsToggle
|
|
||||||
.scrollIntoView(in: app.scrollViews.firstMatch, direction: .up)
|
|
||||||
settingsScreen.tapAnalyticsToggle()
|
settingsScreen.tapAnalyticsToggle()
|
||||||
|
|
||||||
captureScreenshot(name: "analytics_toggled")
|
captureScreenshot(name: "analytics_toggled")
|
||||||
|
|||||||
Reference in New Issue
Block a user