1

アプリケーションでコンテキスト メニューを呼び出したい。

ツリーにアイテムがないという問題。

ビューをアクティブにしてから、コンテキスト メニューを開きたいと思います。

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

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

その後、エラーメッセージが表示されました

ツリーにアイテムがなくても contextMeny を開く方法を教えてください。

4

2 に答える 2

0

これを行う直接的な方法がないためです。コンテキストメニューを開くためのショートカットがあると思います。

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

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

ContextMenuAppears は、目的のコンテキスト メニューが表示されるのを待機する ICondition です。

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

}
于 2013-07-04T08:39:51.067 に答える