6

I have a custom UIView subclass that contains a grid of cells, each of which are also custom UIView subclasses.

I'm interested in using the Keep It Functional test framework, which requires that every view have an acccessibilityLabel.

How do I configure the cell classes to have accessibility labels, so I can refer to them individually in my tests?

Andriy
  • 2,767
  • 2
  • 21
  • 29
Bill
  • 44,502
  • 24
  • 122
  • 213
  • possible duplicate of [Making a programmatic iOS UIView fully accessible](http://stackoverflow.com/questions/6332708/making-a-programmatic-ios-uiview-fully-accessible) – Jim Puls Feb 18 '12 at 04:30
  • You can just set an accessibility label on each subview. – Jim Puls Feb 18 '12 at 04:31
  • @JimPuls, the problem is that there doesn't appear to be an accessibilityLabel method defined on the subviews. – Bill Feb 18 '12 at 14:19

1 Answers1

13

I think my autocomplete was lying to me. All I had to do was:

[gridCell setIsAccessibilityElement:YES];
[gridCell setAccessibilityLabel:[NSString stringWithFormat:@"cell-%d", cellIndex]];
Bill
  • 44,502
  • 24
  • 122
  • 213
  • 2
    I'd argue that for UI testing, you should actually be using the accessibilityIdentifier, not the label. The label gets localized. The identifier doesn't. It was actually added specifically for automated UI testing... exactly what you're doing here. – Mark A. Donohoe Sep 06 '16 at 19:45