iOS UITest: How to test custom accessibility actions?
Asked Answered
G

2

8

I want to support VoiceOver. I have an UIButton inside of an UITableViewCell. According to a best practice I have disabled the button for accessibility (.isAccessibilityElement = false) and implemented a custom accessibility action for the cell (accessibilityCustomActions, NSAccessibilityCustomAction).

This way VoiceOver would not find and read the button as an own element. To make the feature behind the button accessible, I have added a custom accessibility action to the cell. With the custom action the user can select the action with swipe up and down. And then perform it with double-tap.

Now I want to test this action with an UITest. It's not possible to access the button inside of an UITest, because its disabled for accessibility.

How can I perform a custom accessibility action inside of an UITest?

Glycogen answered 19/11, 2018 at 11:36 Comment(1)
I am not sure if you should write UITest for voice over as it needs user interaction. The core requirement of the feature itself is user interaction. And automation does not involve user interaction.Specialist
G
1

Don't know if I got your question correct or if this would work, but you can try coordinate(withNormalizedOffset:) function to click on that UIButton

Eg.

let buttonRectMidX = 300.0
let cellWidth = 320.0
let buttonRectMidY = 25.0
let cellHeight = 50.0


app.tables.firstMatch
    .cells.element(boundBy: 2)
    .coordinate(withNormalizedOffset: CGVector(dx: buttonRectMidX / cellWidth, dy: buttonRectMidY / cellHeight))
    .tap()

Gabfest answered 20/2, 2019 at 7:51 Comment(0)
R
1

How can I perform a custom accessibility action inside of an UITest?

Actually, you can't with {Xcode 11, iOS 13} and even if you can get an array of actions in UITest, it's nil and you can't fire the selectors from XCUITEST (UI tests don't get code-level access to the app as unit tests do).

Testing manually is currently the only way to test accessibility custom actions with VoiceOver.

Take a look at this answer given by an Apple engineer during the WWDC 2019.

Romberg answered 2/5, 2019 at 13:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.