Issue #690

Use accessibilityElements to specify containment for contentView and buttons. You can use Accessibility Inspector from Xcode to verify.

class ArticleCell: UICollectionViewCell {
    let authorLabel: UILabel
    let dateLabel: UILabel

    let viewLabel: UILabel
    let deleteButton: UIButton

    private func setupAccessibility() {
        contentView.isAccessibilityElement = true
        contentView.accessibilityLabel = "This article is written by Nobita on Dec 4th 2020"

        viewLabel.isAccessibilityElement = true // Default is false
        viewLabel.accessibilityTraits.insert(.button) // Treat UILabel as button to VoiceOver

        accessibilityElements = [contentView, viewLabel, deleteButton]
        isAccessibilityElement = false
    }
}

This works OK under Voice Over and Accessibility Inspector. However in iOS 14 UITests, only the contentView is recognizable. The workaround is to use XCUICoordinate

let deleteButton = cell.buttons["Delete article"]
if deleteButton.waitForExistence(timeout: 1) {
    deleteButton.tap()
} else {
    let coordinate = cell.coordinate(
        withNormalizedOffset: CGVector(dx: 0.9, dy: 0.9)
    )
    coordinate.tap()
}

Updated at 2020-11-04 09:42:05