Fix TokenStorage stale cache bug and add user-friendly error messages
- Fix TokenStorage.getToken() returning stale cached token after login/logout - Add comprehensive ErrorMessageParser with 80+ error code mappings - Add Suite9 and Suite10 UI test files for E2E integration testing - Fix accessibility identifiers in RegisterView and ResidenceFormView - Fix UITestHelpers logout to target alert button specifically - Update various UI components with proper accessibility identifiers 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -17,39 +17,41 @@ struct UITestHelpers {
|
||||
return
|
||||
}
|
||||
|
||||
// User is logged in, need to log them out
|
||||
let profileTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Profile'")).firstMatch
|
||||
if profileTab.exists {
|
||||
profileTab.tap()
|
||||
// Check if we have a tab bar (logged in state)
|
||||
let tabBar = app.tabBars.firstMatch
|
||||
guard tabBar.exists else { return }
|
||||
|
||||
// Navigate to Residences tab first
|
||||
let residencesTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Residences'")).firstMatch
|
||||
if residencesTab.exists {
|
||||
residencesTab.tap()
|
||||
sleep(1)
|
||||
}
|
||||
|
||||
// Tap settings button
|
||||
let settingsButton = app.buttons[AccessibilityIdentifiers.Navigation.settingsButton]
|
||||
if settingsButton.waitForExistence(timeout: 3) && settingsButton.isHittable {
|
||||
settingsButton.tap()
|
||||
sleep(1)
|
||||
}
|
||||
|
||||
// Find and tap logout button
|
||||
let logoutButton = app.buttons[AccessibilityIdentifiers.Profile.logoutButton]
|
||||
if logoutButton.waitForExistence(timeout: 3) {
|
||||
logoutButton.tap()
|
||||
sleep(1)
|
||||
|
||||
let logoutButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Logout' OR label CONTAINS[c] 'Log Out' OR label CONTAINS[c] 'Sign Out'")).firstMatch
|
||||
if logoutButton.waitForExistence(timeout: 5) {
|
||||
logoutButton.tap()
|
||||
sleep(1)
|
||||
|
||||
// Tap the "Log Out" button on the alert
|
||||
let alertLogoutButton = app.alerts.buttons["Log Out"]
|
||||
if alertLogoutButton.exists {
|
||||
alertLogoutButton.tap()
|
||||
sleep(2)
|
||||
} else {
|
||||
// Fallback to broader search if exact match not found
|
||||
let confirmButton = app.alerts.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Logout' OR label CONTAINS[c] 'Log Out' OR label CONTAINS[c] 'Confirm' OR label CONTAINS[c] 'Yes'")).firstMatch
|
||||
if confirmButton.exists {
|
||||
confirmButton.tap()
|
||||
sleep(2)
|
||||
}
|
||||
// Confirm logout in alert if present - specifically target the alert's button
|
||||
let alert = app.alerts.firstMatch
|
||||
if alert.waitForExistence(timeout: 2) {
|
||||
let confirmLogout = alert.buttons["Log Out"]
|
||||
if confirmLogout.exists {
|
||||
confirmLogout.tap()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if user is on verify screen after previous test
|
||||
let logoutButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Logout'")).firstMatch
|
||||
if logoutButton.exists {
|
||||
logoutButton.tap()
|
||||
sleep(2)
|
||||
}
|
||||
|
||||
sleep(2)
|
||||
|
||||
// Verify we're back on login screen
|
||||
XCTAssertTrue(welcomeText.waitForExistence(timeout: 5), "Failed to log out - Welcome Back screen should appear after logout")
|
||||
@@ -61,25 +63,34 @@ struct UITestHelpers {
|
||||
/// - username: The username/email to use for login
|
||||
/// - password: The password to use for login
|
||||
static func login(app: XCUIApplication, username: String, password: String) {
|
||||
let usernameField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'email'")).firstMatch
|
||||
// Find username field by accessibility identifier
|
||||
let usernameField = app.textFields[AccessibilityIdentifiers.Authentication.usernameField]
|
||||
XCTAssertTrue(usernameField.waitForExistence(timeout: 5), "Username field should exist")
|
||||
usernameField.tap()
|
||||
usernameField.typeText(username)
|
||||
|
||||
let passwordField = app.secureTextFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'password'")).firstMatch
|
||||
XCTAssertTrue(passwordField.exists, "Password field should exist")
|
||||
// Find password field - it could be TextField (if visible) or SecureField
|
||||
var passwordField = app.secureTextFields[AccessibilityIdentifiers.Authentication.passwordField]
|
||||
if !passwordField.exists {
|
||||
passwordField = app.textFields[AccessibilityIdentifiers.Authentication.passwordField]
|
||||
}
|
||||
XCTAssertTrue(passwordField.waitForExistence(timeout: 3), "Password field should exist")
|
||||
passwordField.tap()
|
||||
passwordField.typeText(password)
|
||||
|
||||
let signInButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Sign In'")).firstMatch
|
||||
XCTAssertTrue(signInButton.exists, "Sign In button should exist")
|
||||
signInButton.tap()
|
||||
// Find and tap login button
|
||||
let loginButton = app.buttons[AccessibilityIdentifiers.Authentication.loginButton]
|
||||
XCTAssertTrue(loginButton.waitForExistence(timeout: 3), "Login button should exist")
|
||||
loginButton.tap()
|
||||
|
||||
// Wait for login to complete
|
||||
sleep(3)
|
||||
}
|
||||
|
||||
/// Ensures the user is logged out before running a test
|
||||
/// - Parameter app: The XCUIApplication instance
|
||||
static func ensureLoggedOut(app: XCUIApplication) {
|
||||
sleep(3)
|
||||
sleep(2)
|
||||
logout(app: app)
|
||||
}
|
||||
|
||||
@@ -88,18 +99,21 @@ struct UITestHelpers {
|
||||
/// - Parameter username: Optional username (defaults to "testuser")
|
||||
/// - Parameter password: Optional password (defaults to "TestPass123!")
|
||||
static func ensureLoggedIn(app: XCUIApplication, username: String = "testuser", password: String = "TestPass123!") {
|
||||
sleep(3)
|
||||
sleep(2)
|
||||
|
||||
// Need to login
|
||||
let usernameField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'email'")).firstMatch
|
||||
// Check if already logged in (tab bar visible)
|
||||
let tabBar = app.tabBars.firstMatch
|
||||
if tabBar.exists {
|
||||
return // Already logged in
|
||||
}
|
||||
|
||||
// Check if on login screen
|
||||
let usernameField = app.textFields[AccessibilityIdentifiers.Authentication.usernameField]
|
||||
if usernameField.waitForExistence(timeout: 5) {
|
||||
login(app: app, username: username, password: password)
|
||||
|
||||
// Wait for main screen to appear
|
||||
let mainTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Residences' OR label CONTAINS[c] 'Tasks'")).firstMatch
|
||||
_ = mainTab.waitForExistence(timeout: 10)
|
||||
} else {
|
||||
return
|
||||
_ = tabBar.waitForExistence(timeout: 10)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user