Testing ActionBar in 4.0

852 views
Skip to first unread message

David Shah

unread,
Jul 6, 2012, 11:50:42 AM7/6/12
to calabash...@googlegroups.com
I'm currently spiking out calabash-android and trying to test navigation when clicking the ActionBar. 
I'm using the ActionBarCompat project for this spike and noticed that, when deployed on a 4.0 emulator, despite the fact that the "Home Icon" of the ActionBar has the id "android.R.id.home" , calabash isn't able to find the id when I use the built in step ' Then I press view with id "home" '

I'm curious to know if anyone else has run into this issue or similar with the ActionBar and if so, what you've done.

It seems that (although VERY hacky) adding this into the onCreate() method of the activity under test:

View home = findViewById(android.R.id.home);

if (home != null)

home.setContentDescription("foobar");

Then using the step ' Then I press "foobar" ' works. Again, this is VERY much a hack so I'm hoping for some better insight into testing ActionBar navigation.

Thanks!

++dave;



Jonas Maturana Larsen

unread,
Jul 6, 2012, 6:14:30 PM7/6/12
to calabash...@googlegroups.com
Hi David,

I don't have much experience with the ActionBarCompat project but here is a little about how ids work in calabash-android. I hope that will enable you to make some connections that I don't see.

The ids that we use in calabash-android is actually injected into the test server when you build it. (That means you have to rebuild everything you have a new version of your app)
We use this weird approach because it enables us to identify views by ids even in obfuscated apps.


Is the view from ActionBarCompat in use when you run on a 4.0 device or is the "build in Android view"?
It could be something related to calabash-android getting the id for the ActionBarCompat view which is not visible and actually not the one you want to click.

What do you think?
Crazy talk?

- Jonas

David Shah

unread,
Jul 9, 2012, 9:08:56 AM7/9/12
to calabash...@googlegroups.com
Jonas,
Thanks for the feedback. To answer your question - when running on a 4.0 device the view isn't coming from the ActionBarCompat library, but is instead the built in Android view.
Can calabash pick up on these default Android view ids? 

The approach you use makes sense and thanks for explaining. Good to know that we can actually use the tool against an obfuscated build!

I'll play around a little more given the info you've provided. Thanks again!
++dave;

Jonas Maturana Larsen

unread,
Jul 9, 2012, 2:17:16 PM7/9/12
to calabash...@googlegroups.com
Calabash can unfortunately not pick up these views.
Which buttons would you like to press? Is it specifically the home button?

I don't know of any way to press the home button from software but it can be done to many other buttons, e.g. the back button.

Frank Li

unread,
Jul 11, 2012, 1:18:47 AM7/11/12
to calabash...@googlegroups.com
You can simply say 
Then I press "{title of the menu item}"
This also apply to tabs.

What I don't know is how to press the overflow item and icon only items...

Jeff Smith

unread,
Jul 31, 2014, 8:27:35 PM7/31/14
to calabash...@googlegroups.com
I was able to get this to work by using using the touch method instead of performAction:

touch("ImageView id:'home'")

David Albers

unread,
Dec 7, 2016, 5:27:04 PM12/7/16
to calabash-android
For what it's worth, none of these answers were working for me on newer versions of Android. I found this to work:
touch("* marked:'Navigate up'")
Which is the contentDescription of the button.
Reply all
Reply to author
Forward
0 new messages