Using accessibilityRepresentation on a TextField breaks the UI tests ability to access the field.
It's pretty simple to reproduce. Having found a workaround that doesn't involve removing the custom representation during UI testing.
struct ContentView: View {
@State var text = ""
var body: some View {
VStack {
TextField(text: $text, axis: .vertical) {
EmptyView()
}
.frame(maxHeight: .infinity, alignment: .topLeading)
.padding(8)
.foregroundStyle(.black) // text color
.tint(.blue) // caret color
.overlay {
RoundedRectangle(cornerRadius: 4)
.fill(.clear)
.strokeBorder(.gray)
}
.accessibilityRepresentation {
// axis: .vertical does weird things to VO
// So the representation is a textfield without that
TextField(text: $text, prompt: nil) {
EmptyView()
}
}
.accessibilityLabel("Text area")
}
.padding()
}
}
func testExample() throws {
// UI tests must launch the application that they test.
let app = XCUIApplication()
app.launch()
let element = app.textFields["Text area"]
// let element = app.textViews["Text area"] // when no customRepresentation used
element.tap()
element.typeText("Hello")
}