简体   繁体   中英

Calabash iOS how to tap the back button item

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}'")

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM