A Maven plugin to manage an Xvfb server. This may be used for headless testing of GUI applications.
Enable the xvfb:run
and xvfb:stop
executions in your module's plugin
configuration.
These goals bind by default to the pre-integration-test
and
post-integration-test
lifecycle phases. When starting up a free X display
port is searched for and Xvfb launched against it, and the process is stopped
after integration tests have run.
The DISPLAY variable corresponding to the temporary Xvfb instance may be passed to integration tests in two ways:
- The default is that the
xvfb:run
goal sets a Maven propertyxvfb.display
which can be used in any other plugin executions (e.g. via the environmentVariables option ofmaven-failsafe-plugin
). - An experimental (and unstable) form of setting the
$DISPLAY
environment variable directly within the executing JVM is also available, but is not recommended.
For example, to run full-UI tycho-surefire-test executions in their own Xvfb
instances, use configuration like the below in your parent pom.xml. Since the
Tycho test plugin binds to the integration-test
phase, the Xvfb plugin will
wrap their execution and set the xvfb.display
plugin value.
<pluginManagement>
<plugins>
<plugin>
<groupId>com.github.zetten</groupId>
<artifactId>xvfb-maven-plugin</artifactId>
<version>${xvfb-maven-plugin.version}</version>
<executions>
<execution>
<id>wrap-tests</id>
<goals>
<goal>run</goal>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<version>${tycho.version}</version>
<configuration>
<useUIHarness>true</useUIHarness>
<environmentVariables>
<DISPLAY>${xvfb.display}</DISPLAY>
</environmentVariables>
</configuration>
</plugin>
</plugins>
</pluginManagement>
The approach was inspired by the Jenkins Xvfb plugin, the Selenium Maven Plugin's Xvfb goal and process-exec-maven-plugin.