Stackoverflow error when using comp.clickOnActionM

2019-06-13 18:42发布

Here is a test function I'm trying to run

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

and this is the delete function

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

The test always fail before opening the overflow menu and this is the faliure trace ... any help ?!!

java.lang.StackOverflowError

for the following method ..

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

The actionBarContextView always come with null and throw the assertion fail message .. so, I'm asking about

actionBarContextView = (ActionBarContextView) getPrivateField("mActionModeView", actionBarSherlock);    

How can I know the private field name ?! BTW. I don't having an access to the source code ...

0条回答
登录 后发表回答