0

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.

Saminathan S
  • 325
  • 2
  • 11

1 Answers1

0

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.