Rebuild UI test foundation with page objects, wait helpers, and screen objects
Replace brittle localized-string selectors and broken wait helpers with a robust, identifier-first UI test infrastructure. All 41 UI tests pass on iOS 26.2 simulator (iPhone 17). Foundation: - BaseUITestCase with deterministic launch helpers (launchClean, launchOffline) - WaitHelpers (waitUntilHittable, waitUntilGone, tapWhenReady) replacing sleep() - UITestID enum mirroring AccessibilityIdentifiers from the app target - Screen objects: TabBarScreen, CameraScreen, CollectionScreen, TodayScreen, SettingsScreen, PlantDetailScreen Key fixes: - Tab navigation uses waitForExistence+tap instead of isHittable (unreliable in iOS 26 simulator) - Tests handle real app state (empty collection, no camera permission) - Increased timeouts for parallel clone execution - Added NetworkMonitorProtocol and protocol-typed DI for testability - Fixed actor-isolation issues in unit test mocks Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
48
PlantGuideUITests/Screens/CameraScreen.swift
Normal file
48
PlantGuideUITests/Screens/CameraScreen.swift
Normal file
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// CameraScreen.swift
|
||||
// PlantGuideUITests
|
||||
//
|
||||
// Screen object for the Camera tab.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
|
||||
struct CameraScreen {
|
||||
let app: XCUIApplication
|
||||
|
||||
// MARK: - Elements
|
||||
|
||||
var captureButton: XCUIElement {
|
||||
app.buttons[UITestID.Camera.captureButton]
|
||||
}
|
||||
|
||||
var permissionDeniedView: XCUIElement {
|
||||
app.otherElements[UITestID.Camera.permissionDeniedView]
|
||||
}
|
||||
|
||||
var openSettingsButton: XCUIElement {
|
||||
app.buttons[UITestID.Camera.openSettingsButton]
|
||||
}
|
||||
|
||||
var previewView: XCUIElement {
|
||||
app.otherElements[UITestID.Camera.previewView]
|
||||
}
|
||||
|
||||
// MARK: - State Checks
|
||||
|
||||
/// Returns `true` if any valid camera state is visible (authorized, denied, or requesting).
|
||||
func hasValidState(timeout: TimeInterval = 5) -> Bool {
|
||||
captureButton.waitForExistence(timeout: timeout)
|
||||
|| permissionDeniedView.waitForExistence(timeout: 2)
|
||||
// Fallback: look for any text that hints at camera permission
|
||||
|| app.staticTexts.matching(
|
||||
NSPredicate(format: "label CONTAINS[c] 'camera'")
|
||||
).firstMatch.waitForExistence(timeout: 2)
|
||||
}
|
||||
|
||||
// MARK: - Actions
|
||||
|
||||
func tapCapture() {
|
||||
captureButton.tapWhenReady()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user