[英]Eclipse: How to close an Eclipse E4 part in SWTBot
I am writing SWTBot test case for my Eclipse E4 application. 我正在为Eclipse E4应用程序编写SWTBot测试用例。
In by setUp() (annotated with @Before), I am opening the part using the menu. 通过setUp()(用@Before注释),我使用菜单打开部件。 I would like to close the same in tearDown (annotated with @After).
我想在tearDown中关闭它(用@After注释)。
I tried with SWTWorkbenchBot, get the active view and close it but the active view instance is null. 我尝试使用SWTWorkbenchBot,获取活动视图并关闭它,但活动视图实例为null。 The view is in fact view and in focus.
视图实际上是视图和焦点。 I can see it.
我能看到它。
The code I have tried 我试过的代码
SWTWorkbenchBot wbBot = new SWTWorkbenchBot();
SWTBotView botView = wbBot.activeView();
botView.close();
Thanks in advance for the help. 先谢谢您的帮助。
I suggest creating SWTWorkbenchBot
reference in setUp() method before your UI is up. 我建议在UI启动之前在setUp()方法中创建
SWTWorkbenchBot
引用。 This should mostly solve your problem. 这应该主要解决你的问题。 Also after making this change you can try using
WidgetMatcherFactory
: 在进行此更改后,您可以尝试使用
WidgetMatcherFactory
:
workBenchBot.widget(org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.widgetOfType( <View_Name>.class ) );
Replace with name of your view. 替换为您的视图名称。 It should return an instance of type
View_Name
. 它应该返回
View_Name
类型的实例。 Then you should create an instance of SWTBOTView
using your view ( View_Name
) and call SWTBOTView#close()
然后你应该使用你的视图(
View_Name
)创建一个SWTBOTView
实例并调用SWTBOTView#close()
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.