How to access menu items from ActionBar?

4,929 views
Skip to first unread message

Eugene Beletskiy

unread,
Feb 9, 2012, 12:18:43 PM2/9/12
to robotium-...@googlegroups.com
Hello, 

Does anybody know how to access menu items located in ActionBar (Honeycomb, ICS) if menu items are a composition of items which belong to Fragments. My Activity doesn't have Menu, but Fragments of which this Activity consists of do have. The solo.pressMenuItem(int x) just doesn't work for me because it searches for the Menu of current Activity which is empty.

Thank a lot.

Eugene Beletskiy

unread,
Feb 9, 2012, 1:04:23 PM2/9/12
to robotium-...@googlegroups.com
Hey, I've found the solution, may be would be helpful for someone else. Not using Robotium, but Android Instrumentation. So, in order to 'click' on the needed item you should use:

getInstrumentation().invokeMenuActionSync(mActivity, R.id.menu_item_id, 0);

Renas

unread,
Mar 25, 2013, 2:44:23 AM3/25/13
to robotium-...@googlegroups.com
Would it be possible for you to send me an application that exhibits the issues that you are experiencing?

/Renas

On Mon, Mar 25, 2013 at 3:14 AM, Simon Drabble <simon....@gmail.com> wrote:
It sure does, but they don't work reliably, if at all.

Robotium 4.0
Android OS 2.3.3
ABS - latest version as of this writing.




On Thursday, January 31, 2013 12:20:46 PM UTC-7, Artur Termenji wrote:
Robotium has methods to work with ActionBar, they are : solo.clickOnActionBarItem(), and solo.clickOnActionBarHomeButton()

среда, 30 января 2013 г., 21:46:56 UTC+2 пользователь RamS написал:
For my current project which makes use of ActionBar to introduce Back Key and Certain Icons as Image Buttons used following codes : 

// Selecting Back function button on Action Bar

ActionBarView actionBar= (ActionBarView)solo.getView(<appPakcageName>.R.id.abs__action_bar);

ImageView backUpKey = (ImageView)actionBar.findViewById(<appPakcageName>.R.id.abs__home);

solo.clickOnView(backUpKey);


// Click on Tools Icon[which is the 3rd Image Button] on Action Bar Menu

solo.clickOnImageButton(2);


Hope this helps!


~Ramdas

--
You received this message because you are subscribed to the Google Groups "Robotium Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotium-develo...@googlegroups.com.
To post to this group, send email to robotium-...@googlegroups.com.
Visit this group at http://groups.google.com/group/robotium-developers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

maguowei2723

unread,
Mar 25, 2013, 3:36:45 AM3/25/13
to robotium-developers
hello all,
 
    I want to get some information from outside of the testcases dynamically,for example, some apks from different channels,only channel id is different,others the same.
 
    my steps are:
    1. install one apk with channel A(all the apks under one folder).
    2. run testcases of apk A.
    3. record some information,like screenshot,testresult ... in channelA directory under sd card.
        the directory like:
            directory A:
                testcase1:screenshot,testresult。
                testcase2:screenshot,testresult。
                ......
            directory B:
                testcase1:screenshot,testresult。
                testcase2:screenshot,testresult。
                ......
            ......         
    4. uninstall application.      
    5. repeat 1,2,3,4 steps with the others' apk.
 
btw, the apks is packaging dynamically,so the order of them not sure.
 
I want to run the same testcases and record the test result of every apk to ensure all the apks work well.So i want to get the channel info in my testcase from out of code.How to catch it?
 
    Anyone can help me?
 
 
maguowei2723,maguow...@gmail.com
2013/3/25

 
 

Anbarasan Jagadeesan

unread,
Apr 25, 2013, 7:48:56 AM4/25/13
to robotium-...@googlegroups.com
hi

you can use

Solo.clickOnMenuItem("youmeanuItem");

//Anbarasu

On Thu, Apr 25, 2013 at 4:50 PM, Richard Lay <rich...@gmail.com> wrote:
Hi, how do you click the home button for ActionBarSherlock on pre ICS?

I have tried solo.onClickView(solo.getView(android.R.id.home)), and also the solo action bar related methods, none of them work.


On Friday, 29 March 2013 09:45:32 UTC+11, Artur Termenji wrote:
Robotium ActionBar methods should work except you are testing an app with ActionBarSherlock on pre ICS. 
An API is different there. 
Also this can depend on the manufacturer.

четверг, 9 февраля 2012 г., 19:18:43 UTC+2 пользователь Eugene Beletskiy написал:
Hello, 

Does anybody know how to access menu items located in ActionBar (Honeycomb, ICS) if menu items are a composition of items which belong to Fragments. My Activity doesn't have Menu, but Fragments of which this Activity consists of do have. The solo.pressMenuItem(int x) just doesn't work for me because it searches for the Menu of current Activity which is empty.

Thank a lot.

--
You received this message because you are subscribed to the Google Groups "Robotium Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotium-develo...@googlegroups.com.
To post to this group, send email to robotium-...@googlegroups.com.
Visit this group at http://groups.google.com/group/robotium-developers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Thanks & Regards
Anbarasan J I PHOTON  I Phresco
DLF-SEZ IT Park I Chennai

Andre Heuner

unread,
Oct 22, 2013, 3:47:42 AM10/22/13
to robotium-...@googlegroups.com
Hi Thomas,
 
Thanks for your great solution - this is definitely working! Only one small issue: I noticed that the method failed on a Galaxy Tab 7'' (Android 2.2). This can be fixed by calling solo.clickOnMenuItem(...) at the end of the method.
 
Cheers!
André
 

log_clear_logs));


Am Donnerstag, 25. April 2013 16:47:40 UTC+2 schrieb Thomas Keller:


Am Donnerstag, 28. März 2013 23:45:32 UTC+1 schrieb Artur Termenji:
Robotium ActionBar methods should work except you are testing an app with ActionBarSherlock on pre ICS. 
An API is different there. 
Also this can depend on the manufacturer.

With ABS the following works:


import com.actionbarsherlock.internal.view.menu.MenuView;

          ... 

public void clickOnActionBarItem(int resourceId) {

        List<View> views = solo.getCurrentViews();

        for (View v : views) {

            if (v instanceof MenuView.ItemView) {

                MenuView.ItemView itemView = (MenuView.ItemView) v;

                if (itemView.getItemData().getItemId() != resourceId) {

                    continue;

                }

                solo.clickOnView(v);

                return;

            }

        }

    } 

However, I did not get solo.clickOnActionBarItem(int) to work on the native action bar. It seems to simply ignore this completely.  

Gualberto Sumano

unread,
Nov 10, 2014, 7:12:56 PM11/10/14
to robotium-...@googlegroups.com
I have spend hours trying to click on action Menu icon but I cannot get to work.  I have try all the above.  I was looking are you code, how can I used it (how do I imported it to eclipse) .  Thank you any information will help. 


On Friday, May 3, 2013 4:45:46 AM UTC-7, Artur Termenji wrote:
Hi, Richard.

I've wrote some code to perform clicks on ActionBar menu and Home items on pre ICS.
You can find it here: https://github.com/atermenji/robotium-actionbarsherlock

четверг, 25 апреля 2013 г., 14:20:57 UTC+3 пользователь Richard Lay написал:
Hi, how do you click the home button for ActionBarSherlock on pre ICS?

I have tried solo.onClickView(solo.getView(android.R.id.home)), and also the solo action bar related methods, none of them work.


On Friday, 29 March 2013 09:45:32 UTC+11, Artur Termenji wrote:
Robotium ActionBar methods should work except you are testing an app with ActionBarSherlock on pre ICS. 
An API is different there. 
Also this can depend on the manufacturer.
четверг, 9 февраля 2012 г., 19:18:43 UTC+2 пользователь Eugene Beletskiy написал:
Hello, 

Tobias Knell

unread,
Nov 26, 2014, 6:15:09 AM11/26/14
to robotium-...@googlegroups.com
I recently built in the  android support libraries into some projects and I'm experiencing the same issue now: none of these methods seem to work. Before using the support library, so using the normal ActionBar, everything worked fine, so I'm definitely using the right IDs. 

The ActionBar (or Toolbar) items are now no longer pressed when using clickOnActionBarItem()  and using clickOnMenuItem() only works for the items that are in the overflow, but not for the ones that are directly shown in the ActionBar. 
Is there any method to make this work?

Renas

unread,
Nov 26, 2014, 8:30:03 AM11/26/14
to robotium-...@googlegroups.com
Hi Tobias,

Please create a ticket for this. 


Best
Renas

--
You received this message because you are subscribed to the Google Groups "Robotium Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotium-develo...@googlegroups.com.
To post to this group, send email to robotium-...@googlegroups.com.

Neil Mole

unread,
Dec 10, 2014, 9:33:51 PM12/10/14
to robotium-...@googlegroups.com
Was this issue 639 which has been closed because the support library is not supported?

I would definitely be interested in the support library (appcompat) being supported, if not maybe there's somewhere central we can collate workarounds?

I've got it clicking on menu items by doing sendKey(Solo.MENU) then getText() then clickOnView(). It works but is a bit slow and I'd hope there's a nicer way?

My current problem is how to tell if a menu item with a checkbox is checked or not. I've hacked it together by finding the view as above then rooting around the view heirachy to find the checkbox view. It's not pretty but I'd be happy to share and see if anyone can improve on it.


Thanks
Neil

Renas Reda

unread,
Dec 11, 2014, 8:31:17 PM12/11/14
to robotium-...@googlegroups.com
Does clickOnMenuItem(String text) work? Otherwise you could try solo.sendKey(Solo.MENU) then clickOnText() or clickInList(). 

As for the checkbox. Have you tried to open the menu and then use isCheckboxChecked()?

Renas
Reply all
Reply to author
Forward
0 new messages