# MyCrib iOS UI Test Strategy ## Current Status: REBUILDING FROM SCRATCH The previous comprehensive tests (50+ tests) were written without proper verification and are failing. We're now taking a methodical approach. ## Phase 1: Foundation Test (IN PROGRESS) ### SimpleLoginTest.swift - ✅ Created with logout-first logic - 🔄 Testing in progress - Contains 2 basic tests: 1. `testAppLaunchesAndShowsLoginScreen()` - Verifies app launches and shows login UI 2. `testCanTypeInLoginFields()` - Verifies we can interact with username/password fields **Key Feature**: `ensureLoggedOut()` helper automatically logs out before each test ## Phase 2: Build Working Tests Incrementally Once SimpleLoginTest works, we'll build: ### Authentication Tests (Priority 1) - Login with valid credentials - Login with invalid credentials - Logout flow - Registration flow - Password reset flow ### Residence Tests (Priority 2) - View residences list - Create residence - Edit residence - Delete residence ### Task Tests (Priority 3) - View tasks - Create task - Mark task in progress - Complete task ## Test Principles 1. **Always logout first** - Each test starts from login screen 2. **Use flexible selectors** - NSPredicate with CONTAINS instead of exact matches 3. **Wait for elements** - Use `waitForExistence(timeout:)` instead of `sleep()` 4. **Test one thing** - Each test focuses on a single user flow 5. **Clean up** - Tests should be independent and repeatable ## How to Run Tests ### In Xcode (Recommended) 1. Open `iosApp.xcodeproj` 2. Select MyCribUITests scheme 3. Press Cmd+U or click diamond icon next to test ### Command Line ```bash xcodebuild test -project iosApp.xcodeproj -scheme MyCribUITests \ -destination 'platform=iOS Simulator,name=iPhone 17' ``` ## Known Issues - Previous comprehensive tests (Comprehensive*Tests.swift) are NOT working - AccessibilityIdentifiers may not all be properly set in views - Need to verify actual UI structure before writing complex tests ## Next Steps 1. ✅ Get SimpleLoginTest passing 2. Add more login/auth tests based on what works 3. Gradually add residence and task tests 4. Delete old failing comprehensive tests once new ones work