使用Robotium-actionbarsherlock扩展的comp.clickOnActionModeOverflowMenuItem(String Text)时出现Stackoverflow错误

时间:2014-03-24 11:47:58

标签: android actionbarsherlock robotium

这是我尝试运行的测试功能

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();
 }

在打开溢出菜单之前测试总是失败,这就是faliure trace ...任何帮助?!!

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);    

我怎么知道私人字段名称?! BTW。我无法访问源代码...

0 个答案:

没有答案