From c7b3c4c21c0f0ebe833129c2be8d0444c0573446 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Thu, 24 Aug 2023 18:20:23 +0300 Subject: [PATCH] Go through more screens in the integration tests --- .../Other/AccessibilityIdentifiers.swift | 6 ++ .../RoomScreen/View/TimelineItemMenu.swift | 2 + .../SettingsScreen/View/SettingsScreen.swift | 2 +- IntegrationTests/Sources/LoginTests.swift | 93 ++++++++++++++----- 4 files changed, 78 insertions(+), 25 deletions(-) diff --git a/ElementX/Sources/Other/AccessibilityIdentifiers.swift b/ElementX/Sources/Other/AccessibilityIdentifiers.swift index b13cc7e1c..405929534 100644 --- a/ElementX/Sources/Other/AccessibilityIdentifiers.swift +++ b/ElementX/Sources/Other/AccessibilityIdentifiers.swift @@ -29,6 +29,7 @@ struct A11yIdentifiers { static let roomNotificationSettingsScreen = RoomNotificationSettingsScreen() static let serverConfirmationScreen = ServerConfirmationScreen() static let sessionVerificationScreen = SessionVerificationScreen() + static let settingsScreen = SettingsScreen() static let softLogoutScreen = SoftLogoutScreen() static let startChatScreen = StartChatScreen() static let roomMemberDetailsScreen = RoomMemberDetailsScreen() @@ -98,6 +99,7 @@ struct A11yIdentifiers { let name = "room-name" let avatar = "room-avatar" let attachmentPicker = "room-attachment_picker" + let timelineItemActionMenu = "room-timeline_item_action_menu" } struct RoomDetailsScreen { @@ -133,6 +135,10 @@ struct A11yIdentifiers { let close = "session_verification-close" } + struct SettingsScreen { + let logout = "settings-logout" + } + struct SoftLogoutScreen { let title = "soft_logout-title" let message = "soft_logout-message" diff --git a/ElementX/Sources/Screens/RoomScreen/View/TimelineItemMenu.swift b/ElementX/Sources/Screens/RoomScreen/View/TimelineItemMenu.swift index 967e7b14c..41d5d244d 100644 --- a/ElementX/Sources/Screens/RoomScreen/View/TimelineItemMenu.swift +++ b/ElementX/Sources/Screens/RoomScreen/View/TimelineItemMenu.swift @@ -157,6 +157,8 @@ public struct TimelineItemMenu: View { } } } + .accessibilityElement(children: .combine) + .accessibilityIdentifier(A11yIdentifiers.roomScreen.timelineItemActionMenu) .presentationDetents([.medium, .large]) .presentationBackground(Color.compound.bgCanvasDefault) .presentationDragIndicator(.visible) diff --git a/ElementX/Sources/Screens/Settings/SettingsScreen/View/SettingsScreen.swift b/ElementX/Sources/Screens/Settings/SettingsScreen/View/SettingsScreen.swift index 7faaf5bd8..f0a810a86 100644 --- a/ElementX/Sources/Screens/Settings/SettingsScreen/View/SettingsScreen.swift +++ b/ElementX/Sources/Screens/Settings/SettingsScreen/View/SettingsScreen.swift @@ -166,7 +166,7 @@ struct SettingsScreen: View { kind: .button { showingLogoutConfirmation = true }) - .accessibilityIdentifier("logoutButton") + .accessibilityIdentifier(A11yIdentifiers.settingsScreen.logout) .alert(L10n.screenSignoutConfirmationDialogTitle, isPresented: $showingLogoutConfirmation) { Button(L10n.screenSignoutConfirmationDialogSubmit, role: .destructive, diff --git a/IntegrationTests/Sources/LoginTests.swift b/IntegrationTests/Sources/LoginTests.swift index a0ea19a45..a25593e5d 100644 --- a/IntegrationTests/Sources/LoginTests.swift +++ b/IntegrationTests/Sources/LoginTests.swift @@ -32,16 +32,11 @@ class LoginTests: XCTestCase { self.runLoginLogoutFlow() } } - - guard let actualDuration = parser.valueForMetric(.clockMonotonicTime) else { - XCTFail("Couldn't retrieve duration") - return - } } - + private func runLoginLogoutFlow() { let app = Application.launch() - + let getStartedButton = app.buttons[A11yIdentifiers.onboardingScreen.signIn] XCTAssertTrue(getStartedButton.waitForExistence(timeout: 10.0)) @@ -79,9 +74,9 @@ class LoginTests: XCTestCase { XCTAssertTrue(nextButton.isEnabled) nextButton.tap() - + sleep(10) - + // Handle analytics prompt screen if app.staticTexts[A11yIdentifiers.analyticsPromptScreen.title].waitForExistence(timeout: 1.0) { // Wait for login and then handle save password sheet @@ -89,12 +84,12 @@ class LoginTests: XCTestCase { if savePasswordButton.waitForExistence(timeout: 10.0) { savePasswordButton.tap() } - + let enableButton = app.buttons[A11yIdentifiers.analyticsPromptScreen.enable] XCTAssertTrue(enableButton.waitForExistence(timeout: 10.0)) enableButton.tap() } - + // This might come in a different order, wait for both. let savePasswordButton = app.buttons["Save Password"] if savePasswordButton.waitForExistence(timeout: 10.0) { @@ -111,44 +106,94 @@ class LoginTests: XCTestCase { // Migration screen may be shown as an overlay. // if that pops up soon enough, we just let that happen and wait let message = app.staticTexts[A11yIdentifiers.migrationScreen.message] - + if message.waitForExistence(timeout: 10.0) { let doesNotExistPredicate = NSPredicate(format: "exists == 0") expectation(for: doesNotExistPredicate, evaluatedWith: message) waitForExpectations(timeout: 300.0) } - + // Welcome screen may be shown as an overlay. if app.buttons[A11yIdentifiers.welcomeScreen.letsGo].waitForExistence(timeout: 1.0) { let goButton = app.buttons[A11yIdentifiers.welcomeScreen.letsGo] XCTAssertTrue(goButton.waitForExistence(timeout: 1.0)) goButton.tap() } - + // Wait for the home screen to become visible. let profileButton = app.buttons[A11yIdentifiers.homeScreen.userAvatar] // Timeouts are huge because we're waiting for the server. XCTAssertTrue(profileButton.waitForExistence(timeout: 300.0)) // Open the first room in the list. - let rooms = app.buttons.matching(NSPredicate(format: "identifier BEGINSWITH %@", A11yIdentifiers.homeScreen.roomNamePrefix)) - rooms.firstMatch.tap() - // Temporary sleep to get it working. - sleep(20) - // Go back to the home screen. - app.navigationBars.firstMatch.buttons["All Chats"].tap() + let firstRoom = app.buttons.matching(NSPredicate(format: "identifier BEGINSWITH %@", A11yIdentifiers.homeScreen.roomNamePrefix)).firstMatch + XCTAssertTrue(firstRoom.waitForExistence(timeout: 10.0)) + firstRoom.tap() + + // Long press on the last message + let lastMessage = app.cells.firstMatch + XCTAssertTrue(lastMessage.waitForExistence(timeout: 10.0)) + lastMessage.press(forDuration: 2.0) + + // Hide the bottom sheet + let timelineItemActionMenu = app.otherElements[A11yIdentifiers.roomScreen.timelineItemActionMenu].firstMatch + XCTAssertTrue(timelineItemActionMenu.waitForExistence(timeout: 10.0)) + timelineItemActionMenu.swipeDown(velocity: .fast) + + // Open the room details + let roomHeader = app.staticTexts["room-name"] + XCTAssertTrue(roomHeader.waitForExistence(timeout: 10.0)) + roomHeader.tap() + + // Open the room member details + let roomMembers = app.buttons["room_details-people"] + XCTAssertTrue(roomMembers.waitForExistence(timeout: 10.0)) + roomMembers.tap() + + // Open the first member's details + let firstRoomMember = app.scrollViews.buttons.firstMatch + XCTAssertTrue(firstRoomMember.waitForExistence(timeout: 10.0)) + firstRoomMember.tap() + + // Go back to the room member details + var backButton = app.buttons["People"] + XCTAssertTrue(backButton.waitForExistence(timeout: 10.0)) + backButton.tap() + + // Go back to the room details + backButton = app.buttons["Back"] + XCTAssertTrue(backButton.waitForExistence(timeout: 10.0)) + backButton.tap() + + // Go back to the room + backButton = app.buttons["Back"] + XCTAssertTrue(backButton.waitForExistence(timeout: 10.0)) + backButton.tap() + + // Go back to the room list + backButton = app.navigationBars.firstMatch.buttons["All Chats"] + XCTAssertTrue(backButton.waitForExistence(timeout: 10.0)) + backButton.tap() // `Failed to scroll to visible (by AX action) Button` https://stackoverflow.com/a/33534187/730924 profileButton.forceTap() - let menuLogoutButton = app.buttons["Sign out"] - XCTAssertTrue(menuLogoutButton.waitForExistence(timeout: 10.0)) - menuLogoutButton.tap() + // Open the settings + let settingsButton = app.buttons["Settings"] + XCTAssertTrue(settingsButton.waitForExistence(timeout: 10.0)) + settingsButton.tap() - let alertLogoutButton = app.buttons["Sign out"] + // Logout + let logoutButton = app.buttons[A11yIdentifiers.settingsScreen.logout] + XCTAssertTrue(logoutButton.waitForExistence(timeout: 10.0)) + logoutButton.tap() + + // Confirm logout + let alertLogoutButton = app.alerts.firstMatch.buttons["Sign out"] XCTAssertTrue(alertLogoutButton.waitForExistence(timeout: 10.0)) alertLogoutButton.tap() + // Check that we're back on the login screen XCTAssertTrue(getStartedButton.waitForExistence(timeout: 10.0)) } }