I have written a SWTBot test for an Eclipse RCP application which opens Eclipse and then opens a view. When run as an SWTBot test, it runs correctly and passes. However, when run in the project's Maven build using Tycho, it fails with the following error message:
org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException: The widget was null.
at org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBot.<init>(AbstractSWTBot.java:104)
at org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBotControl.<init>(AbstractSWTBotControl.java:47)
at org.eclipse.swtbot.swt.finder.widgets.SWTBotShell.<init>(SWTBotShell.java:49)
at org.eclipse.swtbot.swt.finder.widgets.SWTBotShell.<init>(SWTBotShell.java:38)
at org.eclipse.swtbot.swt.finder.SWTBotFactory.activeShell(SWTBotFactory.java:376)
at org.eclipse.swtbot.swt.finder.SWTBotFactory.menu(SWTBotFactory.java:210)
at org.eclipse.swtbot.swt.finder.SWTBotFactory.menu(SWTBotFactory.java:200)
at org.eclipse.ice.viz.service.test.PlotEditorTester.checkPlotEditorFileAssociation(PlotEditorTester.java:143)
The line it fails on is:
bot.menu("Window").menu("Show View").menu("Project Explorer").click();
Specifically, it can't find the "Window" menu. It apparently isn't getting an Eclipse window. I have tried explicitly opening a workbench window like so, but it did not change the error:
UIThreadRunnable.syncExec(new VoidResult() {
public void run() {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().forceActive();
}
});
The test bundle's pom.xml file includes this:
<build>
<plugins>
<!-- Configure the build to handle SWTBot -->
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<useUIHarness>true</useUIHarness>
<useUIThread>false</useUIThread>
<product>org.eclipse.sdk.ide</product>
<application>org.eclipse.ui.ide.workbench</application>
</configuration>
</plugin>
</plugins>
</build>
What am I doing wrong and how do I fix it?
Edit: I found the problem. I needed to add the following dependency to my pom.xml file, inside the <configuraiton> node.
<dependencies>
<dependency>
<type>p2-installable-unit</type>
<artifactId>org.eclipse.sdk.feature.group</artifactId>
</dependency>
</dependencies>
With that, Maven opens an Eclipse instance to run the test in, allowing it to succeed.
[Updated on: Fri, 10 July 2015 17:24]
Report message to a moderator