0

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 ?

Farzad
  • 842
  • 2
  • 9
  • 26
Mona101ma
  • 675
  • 2
  • 7
  • 25

3 Answers3

1

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

getInstrumentation().invokeMenuActionSync(solo.getCurrentActivity(), R.id.my_menu_item_id, 0);
Dave C
  • 928
  • 6
  • 12
  • I tried it but the function invokeMenuActionSync requires the id as int and the main project has all Ids an strings .. – Mona101ma Mar 31 '14 at 13:48
  • I'm not sure exactly what you mean by the IDs as strings. Can you post code for where the IDs are defined? You might want to check out ExtSolo, a Robotium extension that lets you pass in some IDs as a String, for example "com.example.id.checkbox1". See http://docs.testdroid.com/_static/extSolodocs/com/bitbar/recorder/extensions/ExtSolo.html – Dave C Mar 31 '14 at 19:43
  • I don't have access to the source code ... but here is the item Id is: "com.softxpert.sds.R.id.action_delete" I used solo.clickOnText((TextView) solo .findViewById("com.softxpert.sds.R.id.action_delete")); And solo.clickOnView(solo.findViewById("com.softxpert.sds.R.id.action_delete")); And the are working well on many devices but with those of small screen sizes, the item is hidden in the contextual actionbar overflow menu and the above methods are not working .. Also as u see the id is string so, I can't use the method u mentioned – Mona101ma Apr 01 '14 at 07:58
1

You can use solo.clickOnActionBarItem(resourceId).

Renas
  • 1,919
  • 1
  • 18
  • 17
  • ClickOnActionBarItem requires the Id to be int and all Ids in the main application are strings – Mona101ma Mar 31 '14 at 13:42
  • They are all ints. Try solo.clickOnActionBarItem(R.id.yourId). – Renas Apr 01 '14 at 05:23
  • The id of the item is: "R.id.action_delete" that's why I'm not able to use the function ... The id is string and the function parameter is int ... – Mona101ma Apr 01 '14 at 07:51
1

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.

ooi
  • 1,062
  • 12
  • 8