Hi I am new to robotium and currently testing android "actionbaritems" in my application, i used the following code ,
assertTrue(solo.searchText("Log In";));
solo.clickOnButton("Log In";);
solo.waitForActivity(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
assertTrue(solo.searchText("Forgot password?";));
solo.clearEditText(0);
solo.enterText(0, "stest123";);
solo.enterText(1, "123456";);
solo.waitForActivity(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
final EditText editText = solo.getEditText(1); // Create a runnable which triggers the
onEditorAction callback Runnable runnable = new Runnable()
{
public void run()
{
editText.onEditorAction(EditorInfo.IME_ACTION_DONE);
}
}; // Use Solo to get the current activity, and pass our runnable to the UI // thread.
solo.getCurrentActivity().runOnUiThread(runnable);
solo.waitForActivity(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
System.out.println(solo.getCurrentActivity().getLocalClassName().toString());
getInstrumentation().invokeContextMenuAction(getActivity(),3,0);
solo.clickOnText("Nearby";);
solo.sleep(1000);
View actionbarItem1 = solo.getView(2);
solo.clickOnView(actionbarItem1);
i cant able to click on the actionbaritem can anyone advise where i went wrong at code? Since i dont have the apk's source i cant pass it through regular methods, any alternative to this or any idea where i went wrong? thanks in advance
You're doing something quite odd here:
View actionbarItem1 = solo.getView(2);
The solo.getView(int id)
method takes an id of a view from the R.id. (just like a path)
You have a class in a file named R.java where all the ids are referenced. When you create a view it generates an id for your View. Each id matches a view.
public static final class id {
public static final int fancy_action_item_id=0x7f07016a;
}
The method findViewById(int id)
will help you get the View you want by giving it the id.
Maybe you should proceed this way:
View actionBarItem1 = yourActivity.findViewById(R.id.fancy_action_item_id);
solo.clickOnView(actionBarItem1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With