0

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).

ThisIsNotMe
  • 349
  • 2
  • 10

1 Answers1

1

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)
    }
}
Roman Zakharov
  • 2,185
  • 8
  • 19
  • Many thanks, you put me on the right track. Using accessibility id I can get at the input fields, for example: app.secureTextFields["sxtPassword"] txtPassword.tapAndType("12345678") – ThisIsNotMe Apr 17 '20 at 10:52