Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ask the iPad to reveal the keyboard in UI Tests when it's hidden. #3389

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion ElementX/Sources/Other/Extensions/XCUIElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import XCTest

extension XCUIElement {
func clearAndTypeText(_ text: String) {
func clearAndTypeText(_ text: String, app: XCUIApplication) {
tapCenter()

app.showKeyboardIfNeeded()

guard let currentValue = value as? String else {
XCTFail("Tried to clear and type text into a non string value")
return
Expand All @@ -29,3 +31,17 @@ extension XCUIElement {
coordinate.tap()
}
}

extension XCUIApplication {
/// Ensures the software keyboard is shown on an iPad when a text field is focussed.
///
/// Note: Whilst this could be added on XCUIElement to more closely tie it to a text field, it requires the
/// app instance anyway, and some of our tests assert that a default focus has been set on the text field,
/// so having a method that would set the focus and show the keyboard isn't always desirable.
func showKeyboardIfNeeded() {
if UIDevice.current.userInterfaceIdiom == .pad, keyboards.count == 0 {
buttons["Keyboard"].tap()
buttons["Show Keyboard"].tap()
}
}
}
6 changes: 4 additions & 2 deletions UITests/Sources/AppLockSetupUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ class AppLockSetupUITests: XCTestCase {
func testCancel() async throws {
app = Application.launch(.appLockSetupFlowUnlock)

app.showKeyboardIfNeeded() // The secure text field is focussed automatically

// Create PIN screen.
try await app.assertScreenshot(.appLockSetupFlowUnlock)

Expand All @@ -134,13 +136,13 @@ class AppLockSetupUITests: XCTestCase {
let textField = app.secureTextFields[A11yIdentifiers.appLockSetupPINScreen.textField]
XCTAssert(textField.waitForExistence(timeout: 10))

textField.clearAndTypeText("2023")
textField.clearAndTypeText("2023", app: app)
}

private func enterDifferentPIN() {
let textField = app.secureTextFields[A11yIdentifiers.appLockSetupPINScreen.textField]
XCTAssert(textField.waitForExistence(timeout: 10))

textField.clearAndTypeText("2233")
textField.clearAndTypeText("2233", app: app)
}
}
12 changes: 6 additions & 6 deletions UITests/Sources/AuthenticationFlowCoordinatorUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class AuthenticationFlowCoordinatorUITests: XCTestCase {
XCTAssertTrue(continueButton.waitForExistence(timeout: 2.0))

// Login Screen: Enter valid credentials
app.textFields[A11yIdentifiers.loginScreen.emailUsername].clearAndTypeText("alice\n")
app.secureTextFields[A11yIdentifiers.loginScreen.password].clearAndTypeText("12345678")
app.textFields[A11yIdentifiers.loginScreen.emailUsername].clearAndTypeText("alice\n", app: app)
app.secureTextFields[A11yIdentifiers.loginScreen.password].clearAndTypeText("12345678", app: app)

try await app.assertScreenshot(.authenticationFlow)

Expand All @@ -48,8 +48,8 @@ class AuthenticationFlowCoordinatorUITests: XCTestCase {
XCTAssertTrue(continueButton.waitForExistence(timeout: 2.0))

// Login Screen: Enter invalid credentials
app.textFields[A11yIdentifiers.loginScreen.emailUsername].clearAndTypeText("alice")
app.secureTextFields[A11yIdentifiers.loginScreen.password].clearAndTypeText("87654321")
app.textFields[A11yIdentifiers.loginScreen.emailUsername].clearAndTypeText("alice", app: app)
app.secureTextFields[A11yIdentifiers.loginScreen.password].clearAndTypeText("87654321", app: app)

// Login Screen: Tap continue
XCTAssertTrue(continueButton.isEnabled)
Expand All @@ -74,7 +74,7 @@ class AuthenticationFlowCoordinatorUITests: XCTestCase {
XCTAssertTrue(continueButton.waitForExistence(timeout: 2.0))

// When entering a username on a homeserver with an unsupported flow.
app.textFields[A11yIdentifiers.loginScreen.emailUsername].clearAndTypeText("@test:server.net\n")
app.textFields[A11yIdentifiers.loginScreen.emailUsername].clearAndTypeText("@test:server.net\n", app: app)

// Then the screen should not allow login to continue.
try await app.assertScreenshot(.authenticationFlow, step: 1)
Expand All @@ -91,7 +91,7 @@ class AuthenticationFlowCoordinatorUITests: XCTestCase {
app.buttons[A11yIdentifiers.serverConfirmationScreen.changeServer].tap()

// Server Selection: Clear the default, enter OIDC server and continue.
app.textFields[A11yIdentifiers.changeServerScreen.server].clearAndTypeText("company.com\n")
app.textFields[A11yIdentifiers.changeServerScreen.server].clearAndTypeText("company.com\n", app: app)

// Server Confirmation: Tap continue button
app.buttons[A11yIdentifiers.serverConfirmationScreen.continue].tap()
Expand Down
4 changes: 2 additions & 2 deletions UITests/Sources/BugReportUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ class BugReportUITests: XCTestCase {
let app = Application.launch(.bugReport)

// Type 4 characters and the send button should be disabled.
app.textViews[A11yIdentifiers.bugReportScreen.report].clearAndTypeText("Text")
app.textViews[A11yIdentifiers.bugReportScreen.report].clearAndTypeText("Text", app: app)
XCTAssert(app.switches[A11yIdentifiers.bugReportScreen.sendLogs].isOn)
XCTAssert(!app.switches[A11yIdentifiers.bugReportScreen.canContact].isOn)
try await app.assertScreenshot(.bugReport, step: 2)

// Type more than 4 characters and send the button should become enabled.
app.textViews[A11yIdentifiers.bugReportScreen.report].clearAndTypeText("Longer text")
app.textViews[A11yIdentifiers.bugReportScreen.report].clearAndTypeText("Longer text", app: app)
XCTAssert(app.switches[A11yIdentifiers.bugReportScreen.sendLogs].isOn)
XCTAssert(!app.switches[A11yIdentifiers.bugReportScreen.canContact].isOn)
try await app.assertScreenshot(.bugReport, step: 3)
Expand Down
4 changes: 2 additions & 2 deletions UITests/Sources/RoomMembersListScreenUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class RoomMembersListScreenUITests: XCTestCase {
let app = Application.launch(.roomMembersListScreenPendingInvites)

let searchBar = app.searchFields.firstMatch
searchBar.clearAndTypeText("alice\n")
searchBar.clearAndTypeText("alice\n", app: app)

try await app.assertScreenshot(.roomMembersListScreenPendingInvites, step: 1)
}
Expand All @@ -28,7 +28,7 @@ class RoomMembersListScreenUITests: XCTestCase {
let app = Application.launch(.roomMembersListScreenPendingInvites)

let searchBar = app.searchFields.firstMatch
searchBar.clearAndTypeText("bob\n")
searchBar.clearAndTypeText("bob\n", app: app)

try await app.assertScreenshot(.roomMembersListScreenPendingInvites, step: 2)
}
Expand Down
2 changes: 1 addition & 1 deletion UITests/Sources/ServerSelectionUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ServerSelectionUITests: XCTestCase {
let app = Application.launch(.serverSelection)

// When typing in an invalid homeserver
app.textFields[A11yIdentifiers.changeServerScreen.server].clearAndTypeText("thisisbad\n") // The tests only accept an address from LoginHomeserver.mockXYZ
app.textFields[A11yIdentifiers.changeServerScreen.server].clearAndTypeText("thisisbad\n", app: app) // The tests only accept an address from LoginHomeserver.mockXYZ

// Then an error should be shown and the confirmation button disabled.
try await app.assertScreenshot(.serverSelection, step: 2)
Expand Down
4 changes: 2 additions & 2 deletions UITests/Sources/StartChatScreenUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ class StartChatScreenUITests: XCTestCase {
func testSearchWithNoResults() async throws {
let app = Application.launch(.startChat)
let searchField = app.searchFields.firstMatch
searchField.clearAndTypeText("None\n")
searchField.clearAndTypeText("None\n", app: app)
XCTAssert(app.staticTexts[A11yIdentifiers.startChatScreen.searchNoResults].waitForExistence(timeout: 1.0))
try await app.assertScreenshot(.startChat, step: 1)
}

func testSearchWithResults() async throws {
let app = Application.launch(.startChatWithSearchResults)
let searchField = app.searchFields.firstMatch
searchField.clearAndTypeText("Bob\n")
searchField.clearAndTypeText("Bob\n", app: app)
XCTAssertFalse(app.staticTexts[A11yIdentifiers.startChatScreen.searchNoResults].waitForExistence(timeout: 1.0))
XCTAssertEqual(app.collectionViews.firstMatch.cells.count, 2)
try await app.assertScreenshot(.startChat, step: 2)
Expand Down
Loading