How to open Overflow menu of contextual actionbar - Robotium

497 Views Asked by At

A Hello,

I was asking how to select an item from overflow menu of contextual actionbar in robotium ?

I tried: Solo.ClickOnMenuItem(Text); Solo.ClickOnText(Text);

And Also I tried to use Robotium-ActionBarSherlock extension but All are not working with me ?

3

There are 3 best solutions below

0
On

Quick and dirty solution you could use to open action bar's overflow menu is to click on screen in the top right corner of the application:

/**
 * Clicks once somewhere close to the top right corner of the application.
 */
public static void clickOnActionBarOverflow(Solo solo) {
    DisplayMetrics metrics = solo.getCurrentActivity().getResources().getDisplayMetrics();

    solo.clickOnScreen(metrics.widthPixels - 2, 50); // assuming notification area on top
}

And hopefully hitting the right thing.

3
On

You can use solo.clickOnActionBarItem(resourceId).

3
On

The way I do this is to subclass from ActivityInstrumentationTestCase2 and then call

getInstrumentation().invokeMenuActionSync(solo.getCurrentActivity(), R.id.my_menu_item_id, 0);