Failed to click action bar on Robotism.

Hi I am new to robotium and currently tested the “actionbaritems” for Android 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 can not click on actionbaritem, can someone tell me where I made a mistake in the code? Since I don’t have an apk source, I can’t go through the usual methods, any alternative to this, or any idea that I made a mistake in? thank you in advance

+4
source share
1 answer

You are doing something rather strange here:

 View actionbarItem1 = solo.getView(2); 

The solo.getView(int id) method takes a view identifier from R.id. (like a way)

You have a class in a file called R.java, where all identifiers are listed. When you create a view, it generates an identifier for your view. Each identifier corresponds to a view.

 public static final class id { public static final int fancy_action_item_id=0x7f07016a; } 

The findViewById(int id) method will help you get the view you want by giving it an identifier. Perhaps you should continue this path:

 View actionBarItem1 = yourActivity.findViewById(R.id.fancy_action_item_id); solo.clickOnView(actionBarItem1); 
+2
source

Source: https://habr.com/ru/post/1485559/


All Articles