How to start mvn test phase on xvfb?

I did some unit tests using fest , now I need to run mvn my test using maven on a headless system. I would like to run a test using Xvfb, but I need help to configure maven to start Xvfb before testing and stop it when everything is done.

+5
source share
3 answers

I actually use this plugin configuration:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
        <execution>
            <id>start-xvfb</id>
            <phase>process-test-classes</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <tasks>
                    <echo message="Starting xvfb ..." />
                    <exec executable="Xvfb" spawn="true">
                        <arg value=":1" />
                    </exec>
                </tasks>
            </configuration>
        </execution>
        <execution>
            <id>shutdown-xvfb</id>
            <phase>test</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <tasks>
                    <echo message="Ending xvfb ..." />
                    <exec executable="killall">
                            <arg value="Xvfb" />
                    </exec>
                </tasks>
            </configuration>
        </execution>
    </executions>
</plugin>

, ( spawn = "true"), Xvfb ( killall), script. , Ubuntu - sudoers, .

shutdown-xvfb , ( ) , . , ( Xvfb , , ), , - Xvfb. , testFailureIgnore = "true" maven-surefire-plugin, , - .

+1

exec-maven-plugin:

: . maven - Xvfb Xvfb .

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>

            <executions>
                <execution>
                    <id>exec-at-test-compile</id>
                    <phase>test-compile</phase> <!-- runs right before 'test' -->
                    <goals>
                        <goal>exec</goal>
                    </goals>
                    <configuration>
                        <executable>/home/anew/bin/manage-xvfb.sh</executable>
                        <arguments>
                            <argument>start</argument>
                        </arguments>
                    </configuration>
                </execution>
                <execution>
                    <id>exec-at-prepare-package</id>
                    <phase>prepare-package</phase> <!-- runs right after 'test' -->
                    <goals>
                        <goal>exec</goal>
                    </goals>
                    <configuration>
                        <executable>/home/anew/bin/manage-xvfb.sh</executable>
                        <arguments>
                            <argument>stop</argument>
                        </arguments>
                    </configuration>
                </execution>
            </executions>
        </plugin>

manage-xvfb.sh script:

#!/bin/bash

XVFB_CMD="sudo /usr/bin/Xvfb :15 -ac -screen 0 1024x768x8"

function stop_xvfb {
  XVFB_PID=`ps ax | pgrep "Xvfb"`
  if [ "${XVFB_PID}" != "" ]; then
    sudo kill ${XVFB_PID}
  fi
}

if [ "${1}" == "start" ]; then
  stop_xvfb
  ${XVFB_CMD} &
elif [ "${1}" == "stop" ]; then
  stop_xvfb
fi 

, NOPASSWD sudoers.

+3

selenium-maven-plugin:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>selenium-maven-plugin</artifactId>

  <executions>
    <execution>
      <id>setup-xvfb</id>
      <phase>pre-integration-test</phase>
      <goals>
        <goal>xvfb</goal>
      </goals>
    </execution>
  </executions>
</plugin>

, . mojohaus, codehaus.org github.com. , selenium-maven-plugin github, github mojohaus.

However, JARs are available on Maven Central , and the plugin can still be used. There is a fork of sources and a site available on github here if you need to find a few more configuration options.

0
source

All Articles