您好我是robotium的新手,目前正在我的应用程序中测试android“actionbaritems”,我使用了以下代码,
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);
我无法点击actionbaritem任何人都可以建议我在代码出错的地方? 既然我没有 apk的来源我不能通过常规方法传递它,任何替代这个或任何想法,我出错? 提前谢谢
答案 0 :(得分:2)
你在做一些很奇怪的事情:
View actionbarItem1 = solo.getView(2);
solo.getView(int id)
方法从R.id获取视图的id。 (就像路径一样)
您在名为R.java的文件中有一个类,其中引用了所有ID。创建视图时,它会为您的视图生成一个ID。每个id都匹配一个视图。
public static final class id {
public static final int fancy_action_item_id=0x7f07016a;
}
方法findViewById(int id)
将通过为其提供ID来帮助您获得所需的视图。
也许你应该这样做:
View actionBarItem1 = yourActivity.findViewById(R.id.fancy_action_item_id);
solo.clickOnView(actionBarItem1);