Question

I want to call to context menu in my application.

The issue that I don't have any items in the tree.

I active my view and then I want to open context menu.

 SWTBotView view = bot.viewByTitle("Project Explorer");

 view.bot.tree().contextMenu("New").click();

then I got error message

Could you please advise me how I can open contextMeny without any item in the tree ?

Was it helpful?

Solution

As there is no direct way to do this. I assume you have a shortcut for opening your context menu.

bot.activeShell().pressShortcut(<your shortcut>);

bot.waitUntil(new ContextMenuAppears(tree,
                "New"));
tree.contextMenu("New").click();

Where ContextMenuAppears is an ICondition which waits for the desired context menu to appear.

public class ContextMenuAppears implements ICondition {

private SWTBotTree swtBotTree;
private String mMenuText;
public TekstContextMenuAppears(SWTBotTree pSwtBotTree, String menuText) {
    swtBotTree = pSwtBotTree;
    mMenuText = menuText;
}

@Override
public boolean test() throws Exception {
    try {           
        return swtBotTree.contextMenu(mMenuText).isVisible();   
    } catch (WidgetNotFoundException e) {
        return false;
    }

}

@Override
public void init(SWTBot bot) {
    // TODO Auto-generated method stub

}

@Override
public String getFailureMessage() {
    // TODO Auto-generated method stub
    return null;
}

}

OTHER TIPS

depending on what you're trying to achieve, you could try going via the file menu instead of the context menu. "new" should work that way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top