I am starting to include some SwiftUI code in my UIKit project. The UIKit project had UI Tests using XCUITest
which, as you may know, can query elements down the UI tree and can even have an identifier to narrow do your elements found.
I have moved over all the accessibility identifiers, hints, labels, and values have been moved over to the SwiftUI components.
In my case, I had a UITableView
which is now a SwiftUI List
. In my UI tests, I would query the UITableView
like this:
let app = XCUIApplication()
let tableCells = app.table.cells["MyCellIdentifier"]
However, while this worked in SwiftUI, it no longer works in SwiftUI's List
. I understand SwiftUI pretty much hides more of the implementation details of how it builds its UI and it may not even be a Table View under the covers but it certainly looks and acts like the UITableView
I was using before.
Does anyone know how to properly test a table view (List) in SwiftUI using XCUITest
or why it doesn't work with the existing test code?
As you can see below, the sample code shows me adding a accessibility identifier to a RowView
but for Accessibility, it gets passed down to the Text
views (StaticText
in the Accessibility tree).