0

Guys just cant figure out how to tap on BackButtonItem from Navigation Bar with Calabash framework, I'm setting accessibilityLabel like this:

self.navigationItem.leftBarButtonItem?.accessibilityLabel = "goBack"

and trying to test it like this with no luck:

touch("* marked:'goBack'")
touch_transition('navigationItemButtonView first',
                       "* marked:'#{goBack}'")

3 Answers3

2

The problem is that UINavigationItem, UITabBarItem, and UIToobarItem are converted, at runtime, to Views. For example, a UITabBarItem is converted to a UIToobarButton. In the conversion, the accessibilityIdentifier and accessibilityLabel are not preserved.

# This will probably get you the left navbar button
query("UINavigationItemButtonView index:0")

There are ways to enforce that an accessibilityIdentifier is preserved, such as making the navigation item from a custom view.

Take a look at the briar bars/navbar.rb for inspiration. I do not recommend using briar in your project; its life is uncertain (I am the maintainer).

jmoody
  • 2,480
  • 1
  • 16
  • 22
1

I'd recommend trying query "all * marked:'goBack'" and if that still doesn't return any results, just try a query "all *" and see if the label shows up in the results.

You could also try setting the accessibilityIdentifier of the view - generally that's the preferred way to set up views for automation.

0

Just updating it might be helpful for someone who wish to use default back button touch('navigationItemButtonView first')

This will take you back. Found from calabash predefined steps.

vinothp
  • 9,939
  • 19
  • 61
  • 103