Android 使用Robotium actionbarsherlock扩展的组件clickOnActionModeOverflowMenuItem(字符串文本)时发生堆栈溢出错误
这是我正在尝试运行的一个测试函数Android 使用Robotium actionbarsherlock扩展的组件clickOnActionModeOverflowMenuItem(字符串文本)时发生堆栈溢出错误,android,actionbarsherlock,robotium,Android,Actionbarsherlock,Robotium,这是我正在尝试运行的一个测试函数 public void testdeleteSingleDocument () throws Exception { Reusable_AddNew addDoc = new Reusable_AddNew(solo); Reusable_FolderAndDocumentActions delDoc = new Reusable_FolderAndDocumentActions(solo); Reusable_HelpFunctions
public void testdeleteSingleDocument () throws Exception {
Reusable_AddNew addDoc = new Reusable_AddNew(solo);
Reusable_FolderAndDocumentActions delDoc = new Reusable_FolderAndDocumentActions(solo);
Reusable_HelpFunctions Help = new Reusable_HelpFunctions(solo);
addDoc.navMenuClick();
String Document = "My Document";
Help.clearAll();
addDoc.createDocument(Document);
addDoc.appLaunch(solo);
delDoc.deleteItem(Document);
}
这是删除功能
public void clickDeleteIcon () throws Exception {
try {
assertTrue(
"Wait for text (id: com.softxpert.sds.R.id.action_delete) failed.",
solo.waitForTextById("com.softxpert.sds.R.id.action_delete",
20000));
solo.clickOnText((TextView) solo
.findViewById("com.softxpert.sds.R.id.action_delete"));
}
catch (AssertionFailedError e){
//android.view.ContextMenu.
//solo.clickLongOnTextAndPress("Delete", 1);
//solo.clickOnText("Delete");
SoloCompatibilityAbs comp = new SoloCompatibilityAbs(getInstrumentation());
comp.clickOnActionModeOverflowMenuItem("Delete");
}
catch (ClassCastException x) {
solo.clickOnView(solo.findViewById("com.softxpert.sds.R.id.action_delete"));
}
assertDeletePopup();
}
在打开溢出菜单之前,测试总是失败,这是错误跟踪。。。有人帮忙吗
java.lang.StackOverflowError
对于以下方法
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);
actionBarContextView = (ActionBarContextView) getPrivateField("mActionModeView", actionBarSherlock);
} 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始终带有null并抛出断言失败消息。。所以,我想问一下
actionBarContextView = (ActionBarContextView) getPrivateField("mActionModeView", actionBarSherlock);
我怎么知道私有字段名?!
顺便说一句,我没有访问源代码的权限 您可以使用资源id,而不是使用文本。但是,这些项目是不可见的操作,在溢出菜单中,所以,我不知道id?使用层次结构查看器工具,您可以看到您需要的根android设备的资源id。@Manidroid。。。非常感谢,我通过代码中的一些更改来解决错误,以获得正确的活动。。但是如果可能的话,嗯,现在有另一个问题。。。我将把它作为一个问题的答案。。。