Robotium testing on options menu item click

3.7k views Asked by At

I want to write a test class where i have to test on click of optionsmenu item(I have 3 items in options menu). so onclicking the options menu item I m showing the list view with the data which I am retrieving from the sd card.

the application should crash if run time exception occurs.

Kindly help me with some code snippet/example.

Here is my code but its not working.

private Solo solo;

@SuppressWarnings("deprecation")
public Mytest(
    super("com.attt.ui",Activity.class);
}

@Override
protected void setUp() throws Exception {
    super.setUp();
    solo = new Solo(getInstrumentation(), getActivity());
}

public void TestOptionsmenuItemclick() {
    solo.sendKey(Solo.MENU);
    solo.sendKey(KeyEvent.KEYCODE_MENU);
    solo.clickOnMenuItem("view");
    solo.assertCurrentActivity("hai", getName());

}

@Override
public void tearDown() throws Exception {
    solo.finishOpenedActivities();
}

     }

Help is always appreciated!

Thanks

4

There are 4 answers

1
maszter On BEST ANSWER

Of course it doesn't work, because it's not C# - test methods should start with "test". By the way calling:

solo.sendKey(Solo.MENU);
solo.sendKey(KeyEvent.KEYCODE_MENU);
solo.clickOnMenuItem("Review");

also doesn't make sense as clickOnMenuItem opens menu and clicks proper text.

Your test method should be like this:

public void testOptionsmenuItemclick() {
    solo.clickOnMenuItem("Review");
    solo.sleep(1000); // give it time to change activity
    solo.assertCurrentActivity("some message", SomeActivity.class);
}
0
thienkhoi tran On

You should update to latest version of robotium to fix this issue.

0
Heitor Colangelo On

I solved with this:

solo.clickOnView(solo.getView(R.id.menu_item_id));
0
Scott LaHay On

Those crazy robotium guys have added this in 5.4.4 (https://github.com/RobotiumTech/robotium/wiki/Changelog)

solo.scrollRecyclerViewToBottom(0);

Which works for me.