为什么使用 SWTBot 时菜单项被禁用?
我已经写了 使用 SWTBot 进行 GUI 测试测试提取方法重构。我使用 editor.selectRange()
来选择要提取到方法中的语句。但是,当我运行单元测试时,“提取方法重构”菜单项被禁用。因此,SWTBot 无法调用重构。
当我们更改 org.eclipse.jdt.ui.actions.ExtractMethodAction 以便始终启用“Extract Method...”菜单项时,我们的 SWTBot 就会通过。但是,SWTBot 应该让我们选择菜单项,而无需破解 org.eclipse.jdt.ui 插件。
包含上述单元测试的整个项目是 可在 github 上找到。我还在 Eclipse 上报告了该问题SWTBot 和 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 should 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.
也许您必须刷新所有待处理事件才能启用菜单。在尝试单击菜单之前添加此循环:
[编辑] 我认为问题是菜单是通过扩展点或条件启用的。检查菜单或底层操作的所有plugin.xml 文件以及在何种条件下启用它。
要触发条件,您可能必须通知工作台有关新选择的信息。检查 http://www.eclipse.org/articles/Article-WorkbenchSelections/article。 html 和 http://www .eclipse.org/articles/article.php?file=Article-action-contribution/index.html
Maybe you must flush any pending events to enable the menu. Add this loop before you try to click on the menu:
[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