I've got a subclass of UIView, let's say it's class DemoView: UIView { }
which contains UILabel and UIButton. I needed to group it and add UIAccessibilityCustomAction so I've overriden the var accessibilityElements: [Any]?
and used union to connect both elements. I've also assigned "Users" string to accessibilityLabel
.
From user perspective this works as it should, VoiceOver reads Users
and then user can select custom action which is named Edit
.
Problem is that I don't know how can I fire this custom action from UITests. I know that XCUIElement
contains array of UICustomActions
and I can get its selector but then what?
The purpose you're tring to reach isn't possible currently with iOS12 and Xcode 10.
The UITesting framework doesn't access the application code as unit tests do: you can't get an instance to perform selector + the array of custom actions is nil when in UITest ⇒ every custom action isn't reachable and then can't be fired at all.
XCUITEST works thanks to the accessibility properties like accessibilityIdentifier
but isn't definitely designed to simply work for VoiceOver (inconceivable and incomprehensible in my view).
I hope that something new with UI testing will be introduced during the next WWDC for REAL accessibility testing.
I talked to Apple Engineers during WWDC19 Accessibility and Testing Labs and they said it is not possible right now. The reason why accessibility is not available during testing are security concerns. What they also said is that they don't use UITests for testing UIAccessibility and when creating accessibility elements support two cases - when there are UITests running and not.
I recommend making a suggestion using Feedback Assistant.