Hello Apple Developer Support,
I am writing to seek assistance with an issue we are experiencing in our SwiftUI application concerning UI test cases.
Our application uses accessibility labels that differ slightly from the display content to enhance VoiceOver support. However, we have encountered a problem where our UI test cases fail when the accessibility label does not match the actual display content.
Currently, we are using accessibility identifiers in our tests, but they only retrieve the accessibility label, leaving us without a method to access the actual display content. This discrepancy is causing our automated tests to fail, as they cannot verify the visual content of the UI elements.
We would greatly appreciate any guidance or solutions you could provide to address this issue. Specifically, we are looking for a way to ensure our UI tests can access both the accessibility label and the actual display content for verification purposes.
For ex:
Problem scenario - setting accessibilityLabel masks access to any displayed content
If an accessibilityLabel is set on a UI element, then it seems to be no-longer possible to check/access the displayed content of that element:
var body: some View {
Text("AAA")
.accessibilityIdentifier("textThing")
.accessibilityLabel("ZZZ") // Different label from the text which is displayed in UI
}
// in test...
func test_ThingExists() {
XCTAssert(app.staticTexts["AAA"].exists) // Fails, cannot find the element
XCTAssertEqual(app.staticTexts["ZZZ"].label, "AAA") // Fails - '.label' is the accessibilityLabel, not the displayed content
XCTAssertEqual(app.staticTexts["ZZZ"].label, "ZZZ") // Passes, but validates the accessibility content, not the displayed content
XCTAssert(app.staticTexts["textThing"].exists) // Passes, but does not check the displayed content
XCTAssertEqual(app.staticTexts["textThing"].label, "AAA") // Fails - '.label' is the accessibilityLabel, not the displayed content
XCTAssertEqual(app.staticTexts["textThing"].label, "ZZZ") // Passes, but validates the accessibility content, not the displayed content
}
element.label still only checks the accessibilityLabel. There is not, it seems, an way back to being able to check the content of the Text element directly.
Thank you for your attention and support. We look forward to your valuable insights.