Every time Apple release a new XCode version, my UI tests fail. And I need to spend days figuring out what needs to be changed in the tests.
Is there something I am missing?
Example:
let tablesQuery = app.tables
let passwordCellsQuery = tablesQuery.cells.containing(.staticText, identifier:"Password")
passwordCellsQuery.children(matching: .secureTextField).element.tap()
passwordCellsQuery.children(matching: .secureTextField).element.typeText("12345678")
let memorableDateDdMmYyyyCellsQuery = tablesQuery.cells.containing(.staticText, identifier:"Memorable Date (dd/mm/yyyy)")
memorableDateDdMmYyyyCellsQuery.children(matching: .secureTextField).element(boundBy: 2).tap()
memorableDateDdMmYyyyCellsQuery.children(matching: .secureTextField).element(boundBy: 2).typeText("1")
memorableDateDdMmYyyyCellsQuery.children(matching: .secureTextField).element(boundBy: 0).tap()
memorableDateDdMmYyyyCellsQuery.children(matching: .secureTextField).element(boundBy: 0).typeText("2")
memorableDateDdMmYyyyCellsQuery.children(matching: .secureTextField).element(boundBy: 1).tap()
memorableDateDdMmYyyyCellsQuery.children(matching: .secureTextField).element(boundBy: 1).typeText("3")
This time around I get "Failed to synthesize event: Neither element nor any descendant has keyboard focus. Event dispatch snapshot: SecureTextField"
It's got to the point that I dread any new XCode release as it ALWAYS breaks all my UI tests, this time it's Version 11.4.1 (11E503a).
Unit tests behave (thankfully).
You should not stick to the autogenerated code.
Write the test code and elements' description by yourself – this way you test will be more stable.
Try to make your code simpler – it will be easier to maintain.
let table = app.tables.element
let passwordCell = table.cells["Password"]
passwordCellsQuery.tapAndType("12345678")
let dateCell = table.cells["Memorable Date (dd/mm/yyyy)"]
dateCell.secureTextFields.element(boundBy: 2).tapAndType("1")
dateCell.secureTextFields.element(boundBy: 0).tapAndType("2")
dateCell.secureTextFields.element(boundBy: 1).tapAndType("3")
extension XCUIElement {
func tapAndType(_ text: String) {
tap()
typeText(text)
}
}