1

Im running into a problem trying to write UI tests using Earl Grey, specifically how to perform a tap on a certain UITabBarItem.

I noticed that tab bar items don't allow for accessibility ID's and labels to be set in the storyboard, and I've tried setting the accessibility label at runtime using barItem.accessibilityLabel = "label" but that does not work when referencing the item using EarlGrey.select(elementWithMatcher: grey_accessibilityLabel("label")).perform(grey_tap())

Is there a way to accomplish this?

raisedandglazed
  • 804
  • 11
  • 29
  • were you able to find the UITabBarItem in the hierarchy printed by `[GREYElementHierarchy hierarchyStringForAllUIWindows]` ? Were you able to find any attributes there? – gran_profaci Jun 21 '17 at 17:46
  • @gran_profaci Yes I can locate them in the hierarchy, and I see the labels that I set listed next to `AX=`. From the documentation I can see that when this is the case, the element must be found by other means. I can use the `grey_kindOfClass` matcher, but since I have multiple tabs with no labels, how do I select a specific item of that class? – raisedandglazed Jun 22 '17 at 03:48
  • Are there no accessibility attributes at all on the elements themselves? You should probably get those added. I'd recommend using `atIndex` to find the element from the list of matched elements. However, we do not guarantee that the order will be the same every time. – gran_profaci Jun 22 '17 at 06:07
  • 1
    @gran_profaci My apologies, Im relatively new to iOS development so Im trying to sort all this out. Im adding the accessibility attributes to the `UITabBarItems` at runtime in my `UITabBarController`. I loop through the items that I get when calling `tabBar.items!`, and call `barItem.accessibilityLabel = "label"`, `barItem.accessibilityIdentifier = "label"`, and `barItem.isAccessibilityElement = true` on each item. The view hierarchy printed in the console only shows my attributes under the `AX=` key, but nowhere else. – raisedandglazed Jun 22 '17 at 11:29

1 Answers1

1

As answered here, you can use this matcher to find the tab bar element.

Matcher example

EarlGrey.selectElement(with: grey_text(tabbarTitle))
    .inRoot(grey_kindOfClass(UITabBar.self))
    .perform(grey_tap())
Vladimir Kaltyrin
  • 621
  • 1
  • 4
  • 16