开发者

Why is a menu item disabled when using SWTBot?

I've written up a GUI test using SWTBot to test the Extract Method refactoring. I use editor.selectRange() to select a statement to extract into a method. But, when I run the unit test, the Extract Method refactoring menu item is disabled. Thus, SWTBot fails to invoke the refactoring.

When we change org.eclipse.jdt.ui.actions.ExtractMethodAction so that the "Extract Method..." menu item is always enabled, our SWTBot passes. But, SWTBot sho开发者_开发问答uld let us select the menu item without hacking the org.eclipse.jdt.ui plugin.

The whole project containing the above unit test is available at github. I've also reported the problem on the Eclipse forum for SWTBot and SWTBot bug tracking system. But, we haven't received a solution from the forum.


Maybe you must flush any pending events to enable the menu. Add this loop before you try to click on the menu:

while(Display.getDefault().readAndDispatch());

[EDIT] I think the problem is that the menu is enabled through an extension point or a condition. Check all the plugin.xml files for the menu or the underlying action and on which condition it becomes enabled.

To trigger the condition, you may have to notify the workbench about the new selection. Check http://www.eclipse.org/articles/Article-WorkbenchSelections/article.html and http://www.eclipse.org/articles/article.php?file=Article-action-contribution/index.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜