Skip to content

Instantly share code, notes, and snippets.

@sworisbreathing
Last active December 14, 2015 04:18
Show Gist options
  • Save sworisbreathing/5026803 to your computer and use it in GitHub Desktop.
Save sworisbreathing/5026803 to your computer and use it in GitHub Desktop.
This is a sample demonstrating how to include HTML reports generated by Cucumber in your Maven project's site documentation. Version numbers and other stuff has been redacted for clarity. `site.xml` should be in `src/site`. `cucumber-reports.xhtml` should be in `src/site/xhtml` This example requires jQuery. If your site uses maven-fluido-skin, t…
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Cucumber Test Reports</title>
</head>
<body>
<script type="text/javascript">
//<![CDATA[
/*
* This script requires jQuery. If we are using Maven Fluido Skin,
* then jQuery will already be loaded.
*/
$(document).ready(function(){
/**
* Adjusts the IFrame's height in order to match the window's
* current size.
*/
function resizeIFrame() {
/*
* Get the window height and the IFrame's top coordinate.
*/
var windowHeight = $(window).height();
var top = $('#cucumber-reports').position().top;
/*
* For aesthetics, let's allow a little bit of padding at
* the bottom. If you don't have a breadcrumb bar, you will
* need to adjust this accordingly to find the IFrame's top
* padding.
*/
var breadcrumbBottom = $('#breadcrumbs').position().top + $('#breadcrumbs').height();
var padding = top - breadcrumbBottom;
/*
* Now set the IFrame's height.
*/
var newHeight = windowHeight - top - padding;
$('#cucumber-reports').height(newHeight);
}
/*
* Any time the window size changes, adjust the IFrame's height
* again.
*/
$(window).resize(resizeIFrame);
/*
* Initially adjust the IFrame's height.
*/
resizeIFrame();
});
//]]>
</script>
<iframe id="cucumber-reports" style="width:100%" src="./cucumber-reports/index.html" />
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<project ...>
...
<properties>
...
<cucumber.options>--format html:${project.build.directory}/cucumber-reports/html</cucumber.options>
</properties>
<dependencies>
...
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
...
<pluginManagement>
<plugins>
...
<!--
Pass configuration to Cucumber during test execution.
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<cucumber.options>${cucumber.options}</cucumber.options>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
...
<!--
During site builds, copy Cucumber's HTML report to the site directory.
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>cucumber-site-reports</id>
<phase>site</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.reporting.outputDirectory}/cucumber-reports</outputDirectory>
<resources>
<resource>
<directory>${project.build.directory}/cucumber-reports/html</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project ...>
...
<body>
...
<menu ...>
...
<item name="Cucumber Test Reports" href="cucumber-reports.html" />
</menu>
</body>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment