Fix the integration tests. (#4084)

* Fix logging/alerts during OIDC cancellation.

- Cancelling from within the web view wasn't being handled since moving the UserIndicatorController into the presenter.
- The WAS canceledLogin error code is also used when the system cancels the login. When the system cancels there's a failure reason included in the error.

* Allow UI tests to tap on any point within a view.

* Make the homeserver optional in integration tests.

* Dismiss the keyboard after entering a username to reveal the password text field.

Do the same after entering the password field too, just in case.

* Add a loop while waiting for the WAS prompt to be shown.
This commit is contained in:
Doug
2025-05-01 12:07:04 +01:00
committed by GitHub
parent d45b232072
commit 3262fb4cab
5 changed files with 84 additions and 52 deletions
+55 -31
View File
@@ -8,54 +8,78 @@
import XCTest
extension XCUIApplication {
private var doesNotExistPredicate: NSPredicate { NSPredicate(format: "exists == 0") }
func login(currentTestCase: XCTestCase) {
let getStartedButton = buttons[A11yIdentifiers.authenticationStartScreen.signIn]
XCTAssertTrue(getStartedButton.waitForExistence(timeout: 10.0))
getStartedButton.tapCenter()
getStartedButton.tap(.center)
let changeHomeserverButton = buttons[A11yIdentifiers.serverConfirmationScreen.changeServer]
XCTAssertTrue(changeHomeserverButton.waitForExistence(timeout: 10.0))
changeHomeserverButton.tapCenter()
let homeserverTextField = textFields[A11yIdentifiers.changeServerScreen.server]
XCTAssertTrue(homeserverTextField.waitForExistence(timeout: 10.0))
homeserverTextField.clearAndTypeText(homeserver, app: self)
let confirmButton = buttons[A11yIdentifiers.changeServerScreen.continue]
XCTAssertTrue(confirmButton.waitForExistence(timeout: 10.0))
confirmButton.tapCenter()
// Wait for server confirmation to finish
let doesNotExistPredicate = NSPredicate(format: "exists == 0")
currentTestCase.expectation(for: doesNotExistPredicate, evaluatedWith: confirmButton)
currentTestCase.waitForExpectations(timeout: 300.0)
let continueButton = buttons[A11yIdentifiers.serverConfirmationScreen.continue]
XCTAssertTrue(continueButton.waitForExistence(timeout: 30.0))
continueButton.tapCenter()
if let homeserver {
let changeHomeserverButton = buttons[A11yIdentifiers.serverConfirmationScreen.changeServer]
XCTAssertTrue(changeHomeserverButton.waitForExistence(timeout: 10.0))
changeHomeserverButton.tap(.center)
let homeserverTextField = textFields[A11yIdentifiers.changeServerScreen.server]
XCTAssertTrue(homeserverTextField.waitForExistence(timeout: 10.0))
homeserverTextField.clearAndTypeText(homeserver, app: self)
let confirmButton = buttons[A11yIdentifiers.changeServerScreen.continue]
XCTAssertTrue(confirmButton.waitForExistence(timeout: 10.0))
confirmButton.tap(.center)
// Wait for server confirmation to finish
currentTestCase.expectation(for: doesNotExistPredicate, evaluatedWith: confirmButton)
currentTestCase.waitForExpectations(timeout: 300.0)
}
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
let webAuthenticationSessionAlertContinueButton = springboard.buttons["Continue"].firstMatch
XCTAssertTrue(webAuthenticationSessionAlertContinueButton.waitForExistence(timeout: 30.0))
webAuthenticationSessionAlertContinueButton.tapCenter()
// On a fresh simulator the webcredentials association is sometimes slow to be resolved.
// This results in an error alert being shown instead of the Web Authentication Session alert.
// Keep looping on the Continue button for ~5 minutes until the Authentication Session is happy.
var remainingAttempts = 10
while !webAuthenticationSessionAlertContinueButton.exists {
let continueButton = buttons[A11yIdentifiers.serverConfirmationScreen.continue]
XCTAssertTrue(continueButton.waitForExistence(timeout: 30.0))
continueButton.tap(.center)
if webAuthenticationSessionAlertContinueButton.waitForExistence(timeout: 30.0) {
break
}
remainingAttempts -= 1
if remainingAttempts <= 0 {
XCTFail("Failed to present the web authentication session.")
}
if alerts.count > 0 {
alerts.firstMatch.buttons["OK"].tap()
}
}
webAuthenticationSessionAlertContinueButton.tap(.center)
let webAuthenticationView = webViews.firstMatch
XCTAssertTrue(webAuthenticationView.waitForExistence(timeout: 10.0))
webAuthenticationView.tap() // Tap the web view to properly focus the app again.
webAuthenticationView.tap(.top) // Tap the web view to properly focus the app again.
let webUsernameTextField = textFields["Username or Email"]
XCTAssertTrue(webUsernameTextField.waitForExistence(timeout: 10.0))
webUsernameTextField.clearAndTypeText(username, app: self)
buttons["Done"].tap() // Dismiss the keyboard so that the password text field is fully hittable.
let webPasswordTextField = secureTextFields["Password"]
XCTAssertTrue(webPasswordTextField.waitForExistence(timeout: 10.0))
webPasswordTextField.clearAndTypeText(password, app: self)
buttons["Done"].tap() // Dismiss the keyboard so that the continue button is fully hittable.
let webLoginButton = webAuthenticationView.buttons["Continue"]
XCTAssertTrue(webLoginButton.waitForExistence(timeout: 10.0))
webLoginButton.tapCenter()
webLoginButton.tap(.center)
// Handle the password saving dialog
let savePasswordButton = buttons["Save Password"]
@@ -63,12 +87,12 @@ extension XCUIApplication {
// Tapping the sheet button while animating upwards fails. Wait for it to settle
sleep(1)
savePasswordButton.tapCenter()
buttons["Not Now"].tap(.center)
}
let webConsentButton = webAuthenticationView.buttons["Continue"]
XCTAssertTrue(webConsentButton.waitForExistence(timeout: 10.0))
webConsentButton.tapCenter()
webConsentButton.tap(.center)
// Wait for login to finish
currentTestCase.expectation(for: doesNotExistPredicate, evaluatedWith: webUsernameTextField)
@@ -88,7 +112,7 @@ extension XCUIApplication {
let profileButton = buttons[A11yIdentifiers.homeScreen.userAvatar]
// `Failed to scroll to visible (by AX action) Button` https://stackoverflow.com/a/33534187/730924
profileButton.tapCenter()
profileButton.tap(.center)
// Make the logout button visible
swipeUp()
@@ -96,12 +120,12 @@ extension XCUIApplication {
// Logout
let logoutButton = buttons[A11yIdentifiers.settingsScreen.logout]
XCTAssertTrue(logoutButton.waitForExistence(timeout: 10.0))
logoutButton.tapCenter()
logoutButton.tap(.center)
// Confirm logout
let alertLogoutButton = alerts.firstMatch.buttons["Sign out"]
XCTAssertTrue(alertLogoutButton.waitForExistence(timeout: 10.0))
alertLogoutButton.tapCenter()
alertLogoutButton.tap(.center)
// Check that we're back on the login screen
let getStartedButton = buttons[A11yIdentifiers.authenticationStartScreen.signIn]