Rewrite all UI tests following fail-fast TEST_RULES patterns
Rewrote 60+ test files to follow honeydue-style test guidelines:
- defaultTimeout=2s, navigationTimeout=5s — fail fast, no long waits
- No coordinate taps (except onboarding paged TabView swipes)
- No sleep(), no retry loops
- No guard...else { return } silent passes — XCTFail everywhere
- All elements by accessibility ID via UITestID constants
- Screen objects for all navigation/actions/assertions
- One logical assertion per test method
Added missing accessibility identifiers to app views:
- MonthView.swift: added AccessibilityID.MonthView.grid to ScrollView
- YearView.swift: added AccessibilityID.YearView.heatmap to ScrollView
Framework rewrites:
- BaseUITestCase: added session ID, localeArguments, extraLaunchArguments
- WaitHelpers: waitForExistenceOrFail, waitUntilHittableOrFail,
waitForNonExistence, scrollIntoView, forceTap
- All 7 screen objects rewritten with fail-fast semantics
- TEST_RULES.md added with non-negotiable rules
Known remaining issues:
- OnboardingTests: paged TabView swipes unreliable on iOS 26 simulator
- SettingsLegalLinksTests: EULA/Privacy buttons too deep in DEBUG scroll
- Customization horizontal picker scrolling needs further tuning
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,11 +2,14 @@
|
||||
// WaitHelpers.swift
|
||||
// Tests iOS
|
||||
//
|
||||
// Centralized, explicit wait helpers. No sleep() allowed.
|
||||
// Centralized wait helpers and element extensions. No sleep() allowed.
|
||||
// Follows fail-fast principles: if an element isn't there, fail immediately.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
|
||||
// MARK: - Test Accessibility Identifiers (mirrors AccessibilityID in app target)
|
||||
|
||||
enum UITestID {
|
||||
enum Tab {
|
||||
static let day = "tab_day"
|
||||
@@ -33,7 +36,6 @@ enum UITestID {
|
||||
static let browseThemesButton = "browse_themes_button"
|
||||
static let clearDataButton = "settings_clear_data"
|
||||
static let analyticsToggle = "settings_analytics_toggle"
|
||||
static let bypassSubscriptionToggle = "settings_bypass_subscription"
|
||||
static let eulaButton = "settings_eula"
|
||||
static let privacyPolicyButton = "settings_privacy_policy"
|
||||
}
|
||||
@@ -104,72 +106,99 @@ enum UITestID {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - XCUIElement Extensions (fail-fast, no retry loops)
|
||||
|
||||
extension XCUIElement {
|
||||
|
||||
/// Wait for the element to exist in the hierarchy.
|
||||
/// - Parameters:
|
||||
/// - timeout: Maximum seconds to wait.
|
||||
/// - message: Custom failure message.
|
||||
/// - Returns: `true` if the element exists within the timeout.
|
||||
/// Wait for element to exist; XCTFail if it doesn't.
|
||||
@discardableResult
|
||||
func waitForExistence(timeout: TimeInterval = 5, message: String? = nil) -> Bool {
|
||||
let result = waitForExistence(timeout: timeout)
|
||||
if !result, let message = message {
|
||||
XCTFail(message)
|
||||
func waitForExistenceOrFail(
|
||||
timeout: TimeInterval,
|
||||
message: String? = nil,
|
||||
file: StaticString = #filePath,
|
||||
line: UInt = #line
|
||||
) -> XCUIElement {
|
||||
if !waitForExistence(timeout: timeout) {
|
||||
XCTFail(message ?? "Expected element to exist: \(self)", file: file, line: line)
|
||||
}
|
||||
return result
|
||||
return self
|
||||
}
|
||||
|
||||
/// Wait until the element is hittable (exists and is enabled/visible).
|
||||
/// - Parameter timeout: Maximum seconds to wait.
|
||||
/// Wait for element to become hittable; XCTFail if it doesn't.
|
||||
@discardableResult
|
||||
func waitUntilHittable(timeout: TimeInterval = 5) -> Bool {
|
||||
let predicate = NSPredicate(format: "isHittable == true")
|
||||
func waitUntilHittableOrFail(
|
||||
timeout: TimeInterval,
|
||||
message: String? = nil,
|
||||
file: StaticString = #filePath,
|
||||
line: UInt = #line
|
||||
) -> XCUIElement {
|
||||
let predicate = NSPredicate(format: "exists == true AND isHittable == true")
|
||||
let expectation = XCTNSPredicateExpectation(predicate: predicate, object: self)
|
||||
let result = XCTWaiter.wait(for: [expectation], timeout: timeout)
|
||||
return result == .completed
|
||||
let result = XCTWaiter().wait(for: [expectation], timeout: timeout)
|
||||
if result != .completed {
|
||||
XCTFail(message ?? "Expected element to become hittable: \(self)", file: file, line: line)
|
||||
}
|
||||
return self
|
||||
}
|
||||
|
||||
/// Tap the element after waiting for it to become hittable.
|
||||
/// - Parameter timeout: Maximum seconds to wait before tapping.
|
||||
func tapWhenReady(timeout: TimeInterval = 5, file: StaticString = #file, line: UInt = #line) {
|
||||
guard waitForExistence(timeout: timeout) else {
|
||||
XCTFail("Element \(identifier) not found after \(timeout)s", file: file, line: line)
|
||||
return
|
||||
}
|
||||
if isHittable {
|
||||
tap()
|
||||
return
|
||||
}
|
||||
|
||||
// Coordinate tap fallback for iOS 26 overlays where XCUI reports false-negative hittability.
|
||||
coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
|
||||
}
|
||||
|
||||
/// Wait for the element to disappear from the hierarchy.
|
||||
/// - Parameter timeout: Maximum seconds to wait.
|
||||
/// Wait for element to disappear; XCTFail if it doesn't.
|
||||
@discardableResult
|
||||
func waitForDisappearance(timeout: TimeInterval = 5) -> Bool {
|
||||
func waitForNonExistence(
|
||||
timeout: TimeInterval,
|
||||
message: String? = nil,
|
||||
file: StaticString = #filePath,
|
||||
line: UInt = #line
|
||||
) -> Bool {
|
||||
let predicate = NSPredicate(format: "exists == false")
|
||||
let expectation = XCTNSPredicateExpectation(predicate: predicate, object: self)
|
||||
let result = XCTWaiter.wait(for: [expectation], timeout: timeout)
|
||||
return result == .completed
|
||||
let result = XCTWaiter().wait(for: [expectation], timeout: timeout)
|
||||
if result != .completed {
|
||||
XCTFail(message ?? "Expected element to disappear: \(self)", file: file, line: line)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
/// Scroll element into view within a scrollable container. Fail-fast if not found.
|
||||
func scrollIntoView(
|
||||
in container: XCUIElement,
|
||||
direction: SwipeDirection = .up,
|
||||
maxSwipes: Int = 5,
|
||||
file: StaticString = #filePath,
|
||||
line: UInt = #line
|
||||
) {
|
||||
if exists && isHittable { return }
|
||||
|
||||
for _ in 0..<maxSwipes {
|
||||
switch direction {
|
||||
case .up: container.swipeUp()
|
||||
case .down: container.swipeDown()
|
||||
case .left: container.swipeLeft()
|
||||
case .right: container.swipeRight()
|
||||
}
|
||||
if exists && isHittable { return }
|
||||
}
|
||||
|
||||
XCTFail("Failed to scroll element into view after \(maxSwipes) swipes: \(self)", file: file, line: line)
|
||||
}
|
||||
|
||||
/// Tap the element if it exists; XCTFail otherwise.
|
||||
func forceTap(file: StaticString = #filePath, line: UInt = #line) {
|
||||
guard exists else {
|
||||
XCTFail("Element does not exist for tap: \(self)", file: file, line: line)
|
||||
return
|
||||
}
|
||||
tap()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - XCUIApplication Extensions
|
||||
|
||||
extension XCUIApplication {
|
||||
|
||||
/// Find any element matching an accessibility identifier.
|
||||
func element(_ identifier: String) -> XCUIElement {
|
||||
let element = descendants(matching: .any).matching(identifier: identifier).firstMatch
|
||||
return element
|
||||
}
|
||||
|
||||
/// Wait for any element matching the identifier to exist.
|
||||
func waitForElement(identifier: String, timeout: TimeInterval = 5) -> XCUIElement {
|
||||
let element = element(identifier)
|
||||
_ = element.waitForExistence(timeout: timeout)
|
||||
return element
|
||||
descendants(matching: .any).matching(identifier: identifier).firstMatch
|
||||
}
|
||||
|
||||
var entryRows: XCUIElementQuery {
|
||||
@@ -180,61 +209,26 @@ extension XCUIApplication {
|
||||
entryRows.firstMatch
|
||||
}
|
||||
|
||||
func tapTab(identifier: String, labels: [String], timeout: TimeInterval = 5, file: StaticString = #file, line: UInt = #line) {
|
||||
/// Tap a tab by identifier, falling back to labels.
|
||||
func tapTab(identifier: String, labels: [String], timeout: TimeInterval = 5, file: StaticString = #filePath, line: UInt = #line) {
|
||||
let idMatch = tabBars.buttons[identifier]
|
||||
if idMatch.waitForExistence(timeout: 1) {
|
||||
idMatch.tapWhenReady(timeout: timeout, file: file, line: line)
|
||||
idMatch.forceTap(file: file, line: line)
|
||||
return
|
||||
}
|
||||
|
||||
for label in labels {
|
||||
let labelMatch = tabBars.buttons[label]
|
||||
if labelMatch.waitForExistence(timeout: 1) {
|
||||
labelMatch.tapWhenReady(timeout: timeout, file: file, line: line)
|
||||
labelMatch.forceTap(file: file, line: line)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
XCTFail("Unable to find tab by id \(identifier) or labels \(labels)", file: file, line: line)
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
func swipeUntilExists(
|
||||
_ element: XCUIElement,
|
||||
direction: SwipeDirection = .up,
|
||||
maxSwipes: Int = 6,
|
||||
timeoutPerTry: TimeInterval = 0.6
|
||||
) -> Bool {
|
||||
if element.waitForExistence(timeout: timeoutPerTry) {
|
||||
return true
|
||||
}
|
||||
|
||||
for _ in 0..<maxSwipes {
|
||||
switch direction {
|
||||
case .up:
|
||||
swipeUp()
|
||||
case .down:
|
||||
swipeDown()
|
||||
case .left:
|
||||
swipeLeft()
|
||||
case .right:
|
||||
swipeRight()
|
||||
@unknown default:
|
||||
swipeUp()
|
||||
}
|
||||
|
||||
if element.waitForExistence(timeout: timeoutPerTry) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
enum SwipeDirection {
|
||||
case up
|
||||
case down
|
||||
case left
|
||||
case right
|
||||
case up, down, left, right
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user