Maven Based Automated Execution of FitNium Acceptance Tests
Intent
To automate execution of the FitNium acceptance tests and generate reports using maven. This is particularly useful in test driven and continuous integration environment.
Motivation
In one of the recent projects we wanted to integrate FitNium acceptance tests with maven based build system.We were using FitNium as it allows us to write and execute Selenium tests using the FitNesse framework but without the need to write a single line of code.
We had created the FitNium test script to test our application. FitNium test script is based on FitNesse doFixture and provides a English language interpretation of the Selenium API.
As part of the maven build system we wanted
- Automatic start up of the servers (Application server, Selenium and FitNesse)
- Execution of the acceptance tests along with the report generation
- Stopping the servers
How we accomplished this forms the basis of this post.
Implementation Details
The tools we are going to use are:
Selenium: Used to automate web application testing
FitNesse: Collaborative tool to write acceptance tests
FitNium: FitNesse + Selenium
Cargo: For deploying applications to containers from ant or maven builds
Maven: Build tool
Assumption here is that the FitNium tests have been created, so we can concentrate on automating the execution of the FitNium tests.
Let’s start with a very simple FitNium test script to serve as an example
!path fitnesse.jar !path fitlibrary.jar !path fitnium.jar !path selenium-java-client-driver.jar !|com.magneticreason.fitnium.BaseFitniumFixture| Set up the browser and connect to selenium |The server is located at | localhost | |The server is on port | 9090 | |Using the browser | *firefox | start at | http://localhost:8080/testApp/pages/login.seam | |check | is selenium initialised | true | |set speed to |50| milliseconds | |set timeout to |50000| milliseconds | |write to debug | starting test | Lets try to login |starting at URL| http://localhost:8080/testApp/pages/login.seam| | enter | admin | in input field | name=home:username_input| | enter | admin | in input field | name=home:password_input| | check | does button With Id | !-home:LoginBtn-! | exist | true | |click button | !-home:LoginBtn-! | |wait For Page To Load For | 5 | seconds | |write to debug | test complete | |close the browser|
Some things worth noting in the FitNium test script above are
- !path <jar> notation refers to the FitNesse class path
- The server is on port should have the port configured for the selenium server. For me it’s 9090
- Starting at URL should point to the URL your application test should start at
Now with the knowledge of the required tools and the test script we will get onto the steps for automating the execution of FitNium tests.
There are mainly five things involved in the whole process
- Installing the application to be tested
- Starting the application server
- Starting the Selenium and FitNesse server
- Running the tests
- Stopping the servers started in step 1, 2 and 3
Step 1: Installing the application:
This can be accomplished using cargo-maven2-plugin.
The pom entry for the plug-in will look like below
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.0</version>
<configuration>
<wait>false</wait>
<container>
<containerId>jboss5x</containerId>
<home>${JBOSS_HOME}</home>
<timeout>300000</timeout>
<systemProperties>
<!-- This is used in jboss-log4j.xml -->
<jboss.server.log.threshold>INFO</jboss.server.log.threshold>
</systemProperties>
</container>
<configuration>
<type>existing</type>
<home>${JBOSS_HOME}\server\default</home>
<properties>
<cargo.rmi.port>1099</cargo.rmi.port>
<cargo.jvmargs>-XX:PermSize=256m -XX:MaxPermSize=512m
</cargo.jvmargs>
</properties>
</configuration>
</configuration>
</plugin>
I am using JBoss-5.1 application server to which the application is deployed.
The containerId is set to the appropriate application server.
The home refers to the application server directory. This property is picked from the environment property in the snippet above.
The configuration here is set to existing i.e. the application is deployed to a running server
home element within the configuration refers to server profile to which the application is installed.
You can find more information on cargo plug-in configuration here
Step 2: Starting the application server
We would want the application server to be started in the pre-integration-test phase and stopped in the post-integration-test phase. This can be directly done by giving execution details for the cargo plug-in as below
<plugin> <groupId>org.codehaus.cargo</groupId> <artifactId>cargo-maven2-plugin</artifactId> <executions> <execution> <id>start-container</id> <phase>pre-integration-test</phase> <goals> <goal>start</goal> </goals> </execution> <execution> <id>stop-container</id> <phase>post-integration-test</phase> <goals> <goal>stop</goal> </goals> </execution> </executions> </plugin>
Step 3: Starting the Selenium and FitNesse servers
The next step is to automatically start Selenium and FitNesse servers. This can easily be accomplished using maven-antrun-plugin and defining execution to start the two in pre-integration-test phase
<profile>
<id>fitnium</id>
<properties>
<fitnium.project>${project.parent.basedir}/testApp-fitnium</fitnium.project>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<execution>
<id>start-selenium-and-fitnesse</id>
<phase>pre-integration-test</phase>
<configuration>
<tasks>
<echo taskname="selenium" message="Starting…" />
<java jar="${fitnium.project}/selenium-server-1.0/selenium-server.jar"
fork="yes" spawn="true">
<arg value="-port" />
<arg value="9090" />
</java>
<echo taskname="fitnesse" message="Starting…" />
<java classname="fitnesseMain.FitNesseMain"
classpath="${fitnium.project}/fitnesse.jar;${fitnium.project}/lib/json.jar"
fork="yes" spawn="true">
<arg value="-p" />
<arg value="7000" />
<arg value="-d" />
<arg value="${fitnium.project}" />
</java>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</plugins>
</build>
</profile>
Make sure that the path to the jars is set correctly as per your environment for the java tasks. The attributes for the selenium tasks are
Port: The port at which the selenium server should listen at. Make sure this matches the port mentioned in the FitNium test script described earlier.
And for the FitNesse are:
-p: port at which the FitNesse server listens
-d: working directory
More details are here
Tip: If you are facing issues starting either the Selenium or FitNesse server try removing spawn=”true” and include failOnError=”true” to know what the exact problem is.
Step 4: Running the tests
The FitNium acceptance tests execution can be supported using fitnesse-maven-plugin.
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>fitnesse-maven-plugin</artifactId> <executions> <execution> <phase>integration-test</phase> <goals> <goal>run</goal> </goals> </execution> </executions> <configuration> <!-- Fitnesse servers list --> <fitnesses> <fitnesse> <hostName>localhost</hostName> <port>7000</port> <pageName>testApp.CreditNetwork</pageName> </fitnesse> </fitnesses> <classPathProvider>maven</classPathProvider> </configuration> </plugin>
We want the tests to be run in the integration-test phase and so have specified the run goal for the plug-in to execute in the integration-test phase.
We also have to specify the FitNesse server configuration i.e. the host name the port and the test page.
classPathProvider – It can take values as maven or fitnesse
The test reports get generated in the target folder for the project. Look onto the maven console for the exact path of the generated reports as per your configuration.
Include <failOnError>true</failOnError> if you want to fail your build on FitNesse test failure.
If it’s maven then we omit the FitNesse based path (!path <jar>) on top of the test scripts as the plug-in will use the project class path instead of the page one.
Step 5: Stopping the servers
The Application server is automatically shutdown in the post-integration-test phase as the cargo plug-in is already configured in this way.
For stopping FitNesse and Selenium we again need a execution defined within the maven-ant-run plug-in as below
<profile>
<id>fitnium</id>
...
...
<execution>
<execution>
<id>stop-selenium-and-fitnesse</id>
<phase>post-integration-test</phase>
<configuration>
<tasks>
<echo taskname="selenium" message="Stopping…" />
<get taskname="selenium"
src="http://localhost:9090/selenium-server/driver/?cmd=shutDown"
dest="result.txt" ignoreerrors="true" />
<echo taskname="selenium" message="Stopping…" />
<java classname="fitnesse.Shutdown" classpath="${fitnium.project}/fitnesse.jar"
fork="yes" spawn="true">
<arg value="-p" />
<arg value="7000" />
<arg value="-h" />
<arg value="localhost" />
</java>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
...
</profile>
Following maven dependencies are needed for the automated FitNium based acceptance tests to work
<dependency> <groupId>org.seleniumhq.selenium.client-drivers</groupId> <artifactId>selenium-java-client-driver</artifactId> <version>1.0-beta-2</version> </dependency> <dependency> <groupId>org.fitnesse</groupId> <artifactId>fitlibrary</artifactId> <version>20060719</version> </dependency> <dependency> <groupId>com.magneticreason.fitnium</groupId> <artifactId>fitnium</artifactId> <version>1.3.0</version> </dependency>
Note: The FitNium dependency has to be installed first to the local repository
Finally the maven command to execute your automated test:
mvn -P fitnium install - In this blog a maven fitnium profile is used which can be used to invoke FitNium tests. If you are not using the maven profile configuration for the FitNium tests, the test will get executed on each install/package.
Filed under: Agile, fitnesse, Maven, Quality Assurance, TDD




I really liked your path to implement a complete test automation. great work.