简体   繁体   中英

Eclipse: How to close an Eclipse E4 part in SWTBot

I am writing SWTBot test case for my Eclipse E4 application.

In by setUp() (annotated with @Before), I am opening the part using the menu. I would like to close the same in tearDown (annotated with @After).

I tried with SWTWorkbenchBot, get the active view and close it but the active view instance is 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. This should mostly solve your problem. Also after making this change you can try using 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 . Then you should create an instance of SWTBOTView using your view ( View_Name ) and call SWTBOTView#close()

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM