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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…