In my test I have a text field with a pre-existing text. I want to delete the content and type a new string.
let textField = app.textFields
textField.tap()
// delete "Old value"
textField.typeText("New value")
When deleting string with hardware keyboard Recording generated for me nothing. After doing the same with software keyboard I got:
let key = app.keys["Usuń"] // Polish name for the key
key.tap()
key.tap()
... // x times
or
app.keys["Usuń"].pressForDuration(1.5)
I was worried that my test is language-dependent so I have created something like this for my supported languages:
extension XCUIElementQuery {
var deleteKey: XCUIElement {
get {
// Polish name for the key
if self["Usuń"].exists {
return self["Usuń"]
} else {
return self["Delete"]
}
}
}
}
It looks nicer in code:
app.keys.deleteKey.pressForDuration(1.5)
but it is very fragile. After quitting from Simulator Toggle software keyboard
was reset and I've got a failing test. My solution doesn't work well with CI testing. How can this be solved to be more universal?
Toggle software keyboard
setting. Is there something else in the text view that could be hiding/dismissing the keyboard? – DimercaprolToggle software keyboard
reset. It is not default for the simulator (and I don't know if this can be changed). This way or the other my method isn't reliable until you can fix language and software keyboard settings from the level of the test (or testing scheme). – Petersburg