From d3b12561b33c1c751b91bb1deb7b04908d57758b Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Tue, 11 Aug 2026 14:42:48 +0300 Subject: [PATCH] Fix XCUITest text entry on all paths --- ElementX/Sources/Other/Extensions/XCUIElement.swift | 7 +++++-- UITests/Sources/AppLockSetupTests.swift | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/ElementX/Sources/Other/Extensions/XCUIElement.swift b/ElementX/Sources/Other/Extensions/XCUIElement.swift index 5e09b0d93..017e4ac1c 100644 --- a/ElementX/Sources/Other/Extensions/XCUIElement.swift +++ b/ElementX/Sources/Other/Extensions/XCUIElement.swift @@ -14,7 +14,10 @@ extension XCUIElement { /// /// Keystrokes are silently dropped when the element hasn't finished taking focus, which corrupts the /// value in ways that are hard to spot later on, so the result is verified and retried before failing. - func clearAndTypeText(_ text: String, app: XCUIApplication) { + /// + /// - Parameter verifyingValue: Whether to read the value back. Pass `false` for a field that submits + /// itself once it is full, such as the PIN screens, as its value can no longer be read at that point. + func clearAndTypeText(_ text: String, app: XCUIApplication, verifyingValue: Bool = true) { for _ in 0..<3 { tap(.center) @@ -33,7 +36,7 @@ extension XCUIElement { typeText(text) // A newline submits the field, which tears it down before its value can be read back. - if text.contains("\n") || containsTypedText(text) { + if text.contains("\n") || !verifyingValue || containsTypedText(text) { return } } diff --git a/UITests/Sources/AppLockSetupTests.swift b/UITests/Sources/AppLockSetupTests.swift index 339db7d62..5b9401afb 100644 --- a/UITests/Sources/AppLockSetupTests.swift +++ b/UITests/Sources/AppLockSetupTests.swift @@ -148,13 +148,13 @@ class AppLockSetupUITests: XCTestCase { let textField = app.secureTextFields[A11yIdentifiers.appLockSetupPINScreen.textField] XCTAssert(textField.waitForExistence(timeout: 10)) - textField.clearAndTypeText("2023", app: app) + textField.clearAndTypeText("2023", app: app, verifyingValue: false) } private func enterDifferentPIN() { let textField = app.secureTextFields[A11yIdentifiers.appLockSetupPINScreen.textField] XCTAssert(textField.waitForExistence(timeout: 10)) - textField.clearAndTypeText("2233", app: app) + textField.clearAndTypeText("2233", app: app, verifyingValue: false) } }