Add onboarding Next buttons and fix accessibility for paged TabView

App-side changes:
- Added "Get Started" / "Continue" next buttons to all onboarding pages
  (Welcome, Day, Time, Style) with onboarding_next_button accessibility ID
- Added onNext callback plumbing from OnboardingMain to each page
- OnboardingMain now uses TabView(selection:) for programmatic page navigation
- Added .accessibilityElement(children: .contain) to all onboarding pages
  to fix iOS 26 paged TabView not exposing child elements
- Added settings_segmented_picker accessibility ID to Settings Picker
- Reduced padding on onboarding pages to keep buttons in visible area

Test-side changes:
- OnboardingScreen: replaced unreliable swipeToNext() with tapNext()
  that taps the accessibility-identified next button
- OnboardingScreen: multi-strategy skip button detection for subscription page
- SettingsScreen: scoped segment tap to picker element to avoid tab bar collision
- CustomizeScreen: simplified horizontal scroll to plain app.swipeLeft()
- OnboardingVotingTests: uses tapNext() to advance to Day page

Passing: OnboardingTests.CompleteFlow, OnboardingVotingTests
Remaining: OnboardingTests.DoesNotRepeat (session state issue),
  Settings scroll (deep elements), Customize horizontal pickers

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Trey T
2026-03-24 18:37:17 -05:00
parent a608ccb718
commit a71104db05
14 changed files with 185 additions and 105 deletions

View File

@@ -28,6 +28,7 @@ enum UITestID {
enum Settings {
static let header = "settings_header"
static let segmentedPicker = "settings_segmented_picker"
static let customizeTab = "settings_tab_customize"
static let settingsTab = "settings_tab_settings"
static let upgradeBanner = "upgrade_banner"
@@ -76,6 +77,7 @@ enum UITestID {
static let subscription = "onboarding_subscription"
static let subscribe = "onboarding_subscribe_button"
static let skip = "onboarding_skip_button"
static let next = "onboarding_next_button"
}
enum Paywall {

View File

@@ -16,8 +16,8 @@ final class OnboardingVotingTests: BaseUITestCase {
let onboarding = OnboardingScreen(app: app)
onboarding.assertVisible()
// Swipe from Welcome to the Day page
onboarding.swipeToNext()
// Advance from Welcome to Day page
onboarding.tapNext()
// Tap Yesterday via accessibility ID
let yesterdayButton = app.element(UITestID.Onboarding.dayYesterday)

View File

@@ -42,7 +42,7 @@ struct CustomizeScreen {
// MARK: - Actions
/// Select a button in a horizontal picker. Scrolls vertically to reveal
/// the section, then scrolls horizontally within the picker to find the button.
/// the section, then scrolls horizontally to find the button.
private func selectHorizontalPickerButton(
_ button: XCUIElement,
file: StaticString = #filePath,
@@ -55,31 +55,23 @@ struct CustomizeScreen {
}
// Phase 1: Scroll settings page vertically to reveal the section
let mainScroll = app.scrollViews.firstMatch
for _ in 0..<5 {
if button.exists && button.isHittable {
button.forceTap(file: file, line: line)
return
}
mainScroll.swipeUp()
app.swipeUp()
}
// Phase 2: Button is in hierarchy but off-screen in horizontal scroll.
// Find the horizontal scroll view containing the button and swipe within it.
// Phase 2: Button exists in tree but is off-screen in a horizontal ScrollView.
// Simple left swipes on the app to scroll horizontally.
if button.exists {
// Swipe left on the button's parent region to scroll the horizontal picker
for _ in 0..<8 {
if button.isHittable {
button.forceTap(file: file, line: line)
return
}
// Swipe left at the button's Y position to scroll the horizontal picker
let buttonFrame = button.frame
let startPoint = app.coordinate(withNormalizedOffset: CGVector(dx: 0.8, dy: 0))
.withOffset(CGVector(dx: 0, dy: buttonFrame.midY))
let endPoint = app.coordinate(withNormalizedOffset: CGVector(dx: 0.2, dy: 0))
.withOffset(CGVector(dx: 0, dy: buttonFrame.midY))
startPoint.press(forDuration: 0.05, thenDragTo: endPoint)
app.swipeLeft()
}
}
@@ -89,7 +81,7 @@ struct CustomizeScreen {
button.forceTap(file: file, line: line)
return
}
mainScroll.swipeRight()
app.swipeRight()
}
XCTFail("Could not find or tap button: \(button)", file: file, line: line)

View File

@@ -16,59 +16,76 @@ struct OnboardingScreen {
// MARK: - Elements
var welcomeScreen: XCUIElement { app.element(UITestID.Onboarding.welcome) }
var subscriptionScreen: XCUIElement { app.element(UITestID.Onboarding.subscription) }
var dayTodayButton: XCUIElement { app.element(UITestID.Onboarding.dayToday) }
var dayYesterdayButton: XCUIElement { app.element(UITestID.Onboarding.dayYesterday) }
var skipButton: XCUIElement { app.element(UITestID.Onboarding.skip) }
var nextButton: XCUIElement { app.element(UITestID.Onboarding.next) }
// MARK: - Actions
/// Swipe to next onboarding page. Uses a coordinate-based drag at the top
/// of the screen to avoid DatePicker/ScrollView gesture conflicts on inner pages.
/// This is the only reliable way to advance a paged TabView in XCUITest.
func swipeToNext() {
// Use slow velocity for reliable paged TabView advancement on iOS 26.
app.swipeLeft(velocity: .slow)
// Allow transition animation to settle
_ = app.waitForExistence(timeout: 0.8)
/// Tap the "Continue" / "Get Started" next button to advance one page.
func tapNext(file: StaticString = #filePath, line: UInt = #line) {
nextButton.waitForExistenceOrFail(
timeout: navigationTimeout,
message: "Onboarding next button should exist",
file: file, line: line
)
// Tap via coordinate the page indicator may overlap the button's hittable area
nextButton.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
// Allow page transition to settle
_ = app.waitForExistence(timeout: 0.5)
}
/// Complete the full onboarding flow: swipe through all screens and skip subscription.
/// Complete the full onboarding flow by tapping through all screens.
func completeOnboarding(file: StaticString = #filePath, line: UInt = #line) {
// Welcome -> swipe
// Welcome -> tap next
welcomeScreen.waitForExistenceOrFail(
timeout: navigationTimeout,
message: "Onboarding welcome screen should appear",
file: file, line: line
)
swipeToNext()
tapNext(file: file, line: line)
// Time -> swipe. The wheel DatePicker can absorb gestures, so retry if needed.
swipeToNext()
if !dayTodayButton.waitForExistence(timeout: 2) {
// Retry the DatePicker may have absorbed the first swipe
swipeToNext()
}
// Day -> select Today, then swipe
// Day -> select Today, tap next
dayTodayButton.waitForExistenceOrFail(
timeout: navigationTimeout,
message: "Day 'Today' button should appear",
file: file, line: line
)
dayTodayButton.forceTap(file: file, line: line)
swipeToNext()
tapNext(file: file, line: line)
// Style -> swipe
swipeToNext()
// Time -> tap next
tapNext(file: file, line: line)
// Subscription -> tap skip
skipButton.waitForExistenceOrFail(
timeout: navigationTimeout,
message: "Skip button should appear on subscription screen",
file: file, line: line
)
skipButton.forceTap(file: file, line: line)
// Style -> tap next
tapNext(file: file, line: line)
// Subscription -> tap skip ("Maybe Later")
// The subscription page may not expose children via accessibility IDs on iOS 26.
// Try multiple strategies.
let strategies: [() -> Bool] = [
{ self.skipButton.waitForExistence(timeout: 2) },
{ self.app.buttons["Maybe Later"].waitForExistence(timeout: 2) },
{ self.app.staticTexts["Maybe Later"].waitForExistence(timeout: 2) },
]
for strategy in strategies {
if strategy() {
break
}
}
if skipButton.exists {
skipButton.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
} else if app.buttons["Maybe Later"].exists {
app.buttons["Maybe Later"].tap()
} else if app.staticTexts["Maybe Later"].exists {
app.staticTexts["Maybe Later"].tap()
} else {
// Last resort: tap at the expected button location (below center)
app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.88)).tap()
}
}
// MARK: - Assertions

View File

@@ -16,8 +16,7 @@ struct SettingsScreen {
// MARK: - Elements
var settingsHeader: XCUIElement { app.element(UITestID.Settings.header) }
var customizeSegment: XCUIElement { app.element(UITestID.Settings.customizeTab) }
var settingsSegment: XCUIElement { app.element(UITestID.Settings.settingsTab) }
var segmentedPicker: XCUIElement { app.element(UITestID.Settings.segmentedPicker) }
var upgradeBanner: XCUIElement { app.element(UITestID.Settings.upgradeBanner) }
var subscribeButton: XCUIElement { app.element(UITestID.Settings.subscribeButton) }
var whyUpgradeButton: XCUIElement { app.element(UITestID.Settings.whyUpgradeButton) }
@@ -30,42 +29,34 @@ struct SettingsScreen {
// MARK: - Actions
func tapCustomizeTab(file: StaticString = #filePath, line: UInt = #line) {
tapSegment(identifier: UITestID.Settings.customizeTab, fallbackLabel: "Customize", file: file, line: line)
tapSegment(label: "Customize", file: file, line: line)
}
func tapSettingsTab(file: StaticString = #filePath, line: UInt = #line) {
tapSegment(identifier: UITestID.Settings.settingsTab, fallbackLabel: "Settings", file: file, line: line)
tapSegment(label: "Settings", file: file, line: line)
}
private func tapSegment(identifier: String, fallbackLabel: String, file: StaticString, line: UInt) {
// On iOS 26, segmented controls may expose buttons by label or by ID.
// Try multiple strategies in order of reliability.
// Strategy 1: Segmented control button by label (most reliable)
let segButton = app.segmentedControls.buttons[fallbackLabel]
if segButton.waitForExistence(timeout: defaultTimeout) && segButton.isHittable {
segButton.tap()
return
}
// Strategy 2: Find a non-tab-bar button with matching label
let tabBarButton = app.tabBars.buttons[fallbackLabel]
let allButtons = app.buttons.matching(NSPredicate(format: "label == %@", fallbackLabel)).allElementsBoundByIndex
for button in allButtons {
if button.isHittable && button.frame != tabBarButton.frame {
/// Tap a segmented control button by label, scoped to the settings picker
/// to avoid collision with the tab bar's "Settings" button.
private func tapSegment(label: String, file: StaticString, line: UInt) {
// Find the segmented picker by its accessibility ID, then find the button within it
let picker = segmentedPicker
if picker.waitForExistence(timeout: defaultTimeout) {
let button = picker.buttons[label]
if button.waitForExistence(timeout: defaultTimeout) && button.isHittable {
button.tap()
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()
// Fallback: segmented control element type
let segButton = app.segmentedControls.buttons[label]
if segButton.waitForExistence(timeout: defaultTimeout) && segButton.isHittable {
segButton.tap()
return
}
XCTFail("Could not find segment '\(fallbackLabel)' by ID or label", file: file, line: line)
XCTFail("Could not find segment '\(label)' in settings picker", file: file, line: line)
}
func tapClearData(file: StaticString = #filePath, line: UInt = #line) {
@@ -79,8 +70,7 @@ struct SettingsScreen {
}
/// 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.
/// Swipes in the center band of the screen (between header and tab bar).
private func scrollToSettingsElement(
_ element: XCUIElement,
maxSwipes: Int,
@@ -90,9 +80,9 @@ struct SettingsScreen {
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))
// Swipe from center-low to center-high, avoiding header area and tab bar
let start = app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.7))
let end = app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.15))
start.press(forDuration: 0.05, thenDragTo: end)
if element.exists && element.isHittable { return }

View File

@@ -26,17 +26,20 @@ final class SettingsTests: BaseUITestCase {
let settingsScreen = TabBarScreen(app: app).tapSettings()
settingsScreen.assertVisible()
// Switch to Settings sub-tab and verify the segment exists
// Switch to Settings sub-tab
settingsScreen.tapSettingsTab()
settingsScreen.settingsSegment
.waitForExistenceOrFail(timeout: defaultTimeout, message: "Settings segment should exist after tapping it")
// Verify picker still exists after switch
settingsScreen.segmentedPicker
.waitForExistenceOrFail(timeout: defaultTimeout, message: "Segmented picker should exist after switching to Settings")
captureScreenshot(name: "settings_subtab")
// Switch back to Customize and verify
// Switch back to Customize
settingsScreen.tapCustomizeTab()
settingsScreen.customizeSegment
.waitForExistenceOrFail(timeout: defaultTimeout, message: "Customize segment should exist after tapping it")
settingsScreen.segmentedPicker
.waitForExistenceOrFail(timeout: defaultTimeout, message: "Segmented picker should exist after switching to Customize")
captureScreenshot(name: "customize_subtab")
}