Calabash iOS how to tap the back button item

830 Views Asked by At

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

There are 3 best solutions below

1
On BEST ANSWER

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.

1
On

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).

0
On

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.