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

This commit is contained in:
Doug
2024-10-10 08:38:40 +01:00
committed by GitHub
parent 2194908ee5
commit 429ce4fe61
7 changed files with 34 additions and 16 deletions
@@ -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
@@ -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()
}
}
}