你好,,, 我正在使用robotium框架来测试Android应用程序,我使用了Robotium-actionbarsherlock扩展来执行上下文操作栏菜单项的点击...
这是我正在使用的功能,,,
public void clickOnActionModeOverflowMenuItem(String text) {
Activity activity = solo.getCurrentActivity();
Log.d("aaaa", activity.toString());
if (!(activity instanceof SherlockFragmentActivity)) {
throw new IllegalStateException("This method should be called only in SherlockFragmentActivity.");
}
ActionBarContextView actionBarContextView = null;
try {
ActionBarSherlock actionBarSherlock = (ActionBarSherlock) invokePrivateMethodWithoutParameters(
SherlockFragmentActivity.class, "getSherlock", activity);
Log.d("eeee", actionBarSherlock.toString());
actionBarContextView = (ActionBarContextView) getPrivateField("mActionModeView", actionBarSherlock);
Log.d("dddd", actionBarContextView.toString());
} catch (Exception ex) {
Log.d(LOG_TAG, "Can not find methods to invoke action mode overflow button.");
}
if (actionBarContextView == null) {
Assert.fail("Contextual actionbar is not shown.");
}
actionBarContextView.showOverflowMenu();
sleeper.sleep();
clicker.clickOnText(text, false, 1, true, 0);
}
所以,我问这条线..
actionBarContextView = (ActionBarContextView) getPrivateField("mActionModeView", actionBarSherlock);
我如何知道私人字段名称? 由于函数失败并抛出null actionBarContextView ...
的断言失败答案 0 :(得分:0)
您可以下载ActionBarSherlock的源代码,它应该显示您要查找的内容。