Skip to content

Commit

Permalink
custom favicon definition
Browse files Browse the repository at this point in the history
  • Loading branch information
bischoffdev committed Jul 9, 2024
1 parent 9fd32d5 commit 34a621f
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 30 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

Back to [Readme](README.md).

## [3.7.0] - UNRELEASED
## [3.7.0] - 2024-07-09

### Added

* Custom favicon
* Custom favicon definition through property (#340)

## [3.6.3] - 2024-06-10

Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ Cluecumber comes in two flavors:
* [__Cluecumber Core__](core) - generates reports from Java code
* [__Cluecumber Maven__](maven) - generates reports from Maven

The look can be adjusted by setting
* optional custom CSS
* optional custom favicon
* Custom parameters

![Cluecumber animation](documentation/img/cluecumber.gif)

A fully generated example report can be [viewed here](https://softwaretester.blog/cluecumber)!
Expand Down
15 changes: 15 additions & 0 deletions core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ _Clear and concise JVM reporting for the Cucumber BDD JSON format_
- [Defining the report start page](#defining-the-report-start-page)
- [Defining a custom report title](#defining-a-custom-report-title)
- [Defining a custom CSS file](#defining-a-custom-css-file)
- [Defining a custom favicon](#defining-a-custom-favicon)
- [Defining custom passed, skipped and failed colors](#defining-custom-passed-skipped-and-failed-colors)
- [Enabling a compact view of multiple runs of the same scenarios](#enabling-a-compact-view-of-multiple-runs-of-the-same-scenarios)
- [Appendix](#appendix)
Expand Down Expand Up @@ -345,6 +346,20 @@ Likewise, if you want to hide elements from the report, you can also add this to
}
```


## Defining a custom favicon

The favicon is displayed in the browser tab and can be customized by setting the `customFavicon` property. This must be
a png file of size 16x16 or 32x32 pixels

![Custom Favicon](../documentation/img/custom_favicon.png)

```java
new CluecumberCore.Builder()
.setCustomFavicon("custom/favicon.png")
.build().generateReports(jsonDirectory, reportDirectory);
```

## Defining custom passed, skipped and failed colors

It is possible to set these properties to change the color scheme for passed, failed and skipped steps and scenarios
Expand Down
14 changes: 14 additions & 0 deletions core/src/main/java/com/trivago/cluecumber/core/CluecumberCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ public class CluecumberCore {

/**
* The constructor for the Cluecumber core.
*
* @param builder The builder instance.
* @throws CluecumberException Thrown in case of any error.
*/
private CluecumberCore(Builder builder) throws CluecumberException {
cluecumberEngine = DaggerCluecumberCoreGraph.create().getCluecumberEngine();
cluecumberEngine.setCustomCssFile(builder.customCssFile);
cluecumberEngine.setCustomFavicon(builder.customFavicon);
cluecumberEngine.setCustomNavigationLinks(builder.customNavigationLinks);
cluecumberEngine.setCustomPageTitle(builder.customPageTitle);
cluecumberEngine.setCustomParameters(builder.customParameters);
Expand Down Expand Up @@ -75,6 +77,7 @@ public void generateReports(final String jsonDirectory, final String reportDirec
*/
public static class Builder {
private String customCssFile;
private String customFavicon;
private LinkedHashMap<String, String> customNavigationLinks;
private String customPageTitle;
private LinkedHashMap<String, String> customParameters;
Expand Down Expand Up @@ -116,6 +119,17 @@ public Builder setCustomCssFile(final String customCssFile) {
return this;
}

/**
* Custom favicon to display in the browser tab.
*
* @param customFavicon The path to a favicon png file.
* @return The {@link Builder}.
*/
public Builder setCustomFaviconFile(final String customFavicon) {
this.customFavicon = customFavicon;
return this;
}

/**
* Custom navigation links to display at the end of the default navigation.
*
Expand Down
Binary file added documentation/img/custom_favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions engine/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ This is the main component that creates the reports; used by [Cluecumber Core](.
and [Cluecumber Maven](../maven).

__Note:__ This is not intended to be used as a standalone dependency. Instead, use [Cluecumber Core](../core) when
generating reports
from code!
generating reports from code!
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,13 @@ public void setCustomCssFile(final String customCss) throws MissingFileException
propertyManager.setCustomCssFile(customCss);
}

public void setCustomFavicon(final String customFavicon) throws MissingFileException {
if (customFavicon == null) {
return;
}
propertyManager.setCustomFaviconFile(customFavicon);
}

/**
* Set a custom color for passed scenarios.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ public String getGeneratedHtmlReportDirectory() {
* @param generatedHtmlReportDirectory The path.
* @throws WrongOrMissingPropertyException Thrown on any error.
*/
public void setGeneratedHtmlReportDirectory(final String generatedHtmlReportDirectory) throws WrongOrMissingPropertyException {
public void setGeneratedHtmlReportDirectory(final String generatedHtmlReportDirectory)
throws WrongOrMissingPropertyException {
if (!isSet(generatedHtmlReportDirectory)) {
throw new WrongOrMissingPropertyException("generatedHtmlReportDirectory");
}
Expand Down Expand Up @@ -198,7 +199,8 @@ public Settings.CustomParamDisplayMode getCustomParametersDisplayMode() {
*/
public void setCustomParametersDisplayMode(String customParametersDisplayMode) {
try {
this.customParametersDisplayMode = Settings.CustomParamDisplayMode.valueOf(customParametersDisplayMode.toUpperCase());
this.customParametersDisplayMode =
Settings.CustomParamDisplayMode.valueOf(customParametersDisplayMode.toUpperCase());
} catch (IllegalArgumentException e) {
logger.warn("Unknown setting for custom parameter page(s): '" + customParametersDisplayMode +
"'. Must be one of " + Arrays.toString(Settings.CustomParamDisplayMode.values()));
Expand Down Expand Up @@ -549,7 +551,9 @@ public void logProperties() {
logger.logInfoSeparator();
}
customParameters.entrySet().stream().map(entry -> "- custom parameter : " +
entry.getKey() + " -> " + entry.getValue()).forEach(logString -> logger.info(logString, DEFAULT));
entry.getKey() + " -> " +
entry.getValue()).forEach(
logString -> logger.info(logString, DEFAULT));
}

logger.logInfoSeparator(DEFAULT);
Expand All @@ -574,18 +578,15 @@ public void logProperties() {
logString -> logger.info(logString, DEFAULT));
}


if (isSet(customCssFile)) {
logger.info("- custom CSS file : " + customCssFile, DEFAULT);
}

if (isSet(customFaviconFile)) {
logger.info("- custom favicon file : " + customFaviconFile, DEFAULT);
}

logger.info("- colors (passed, failed, skipped) : " +
customStatusColorPassed + ", " + customStatusColorFailed + ", " + customStatusColorSkipped, DEFAULT);

logger.logInfoSeparator(DEFAULT);
}

Expand All @@ -606,7 +607,8 @@ private boolean isSet(final String string) {
* @param colorPropertyName The name of the color property.
* @throws WrongOrMissingPropertyException Thrown if the color is invalid.
*/
private void checkHexColorValidity(String color, String colorPropertyName) throws WrongOrMissingPropertyException {
private void checkHexColorValidity(String color, String colorPropertyName)
throws WrongOrMissingPropertyException {
if (!Pattern.compile(COLOR_PATTERN).matcher(color).matches()) {
throw new WrongOrMissingPropertyException(colorPropertyName);
}
Expand All @@ -630,7 +632,8 @@ public void setStartPage(final String startPage) {
try {
this.startPage = Settings.StartPage.valueOf(startPage.toUpperCase());
} catch (IllegalArgumentException e) {
logger.warn("Unknown start page '" + startPage + "'. Must be one of " + Arrays.toString(Settings.StartPage.values()));
logger.warn("Unknown start page '" + startPage + "'. Must be one of " +
Arrays.toString(Settings.StartPage.values()));
this.startPage = Settings.StartPage.ALL_SCENARIOS;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void generateReport(final AllScenariosPageCollection allScenariosPageColl

boolean redirectToFirstScenarioPage =
propertyManager.getStartPage() == Settings.StartPage.ALL_SCENARIOS &&
allScenariosPageCollection.getTotalNumberOfScenarios() == 1;
allScenariosPageCollection.getTotalNumberOfScenarios() == 1;

generateStartPage(redirectToFirstScenarioPage);
for (PageVisitor visitor : visitors) {
Expand Down Expand Up @@ -154,11 +154,9 @@ private void copyCustomCss(final String reportDirectory) throws CluecumberExcept
*/
private void copyCustomFavicon(final String reportDirectory) throws CluecumberException {
String customFavicon = propertyManager.getCustomFaviconFile();
System.out.println("customFavicon: " + customFavicon);
if (customFavicon != null && !customFavicon.isEmpty()) {
fileSystemManager.copyResource(customFavicon, reportDirectory + "/img/favicon.ico");
fileSystemManager.copyResource(customFavicon, reportDirectory + "/img/favicon.png");
} else {
System.out.println("copying default favicon");
copyFileFromJarToReportDirectory("/img/favicon.png");
}
}
Expand Down
3 changes: 3 additions & 0 deletions examples/maven-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
<!-- Optional custom CSS for custom styling -->
<!-- <customCss>custom/custom.css</customCss> -->

<!-- Optional custom favicon (needs to be a png) -->
<!-- <customFavicon>custom/favicon.png</customFavicon> -->

<!-- Optional properties to expand scenario hooks, step hooks, doc strings, attachments and step outputs when scenario details are shown (default: false) -->
<expandSubSections>false</expandSubSections>
<expandBeforeAfterHooks>true</expandBeforeAfterHooks>
Expand Down
6 changes: 3 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
build-and-test:
mvn clean install
mvn verify -f=examples/maven-example -e
(cd examples/maven-example && mvn verify -e)
open examples/maven-example/target/cluecumber-report/pages/scenario-detail/scenario_1.html

show-versions:
mvn versions:display-dependency-updates
mvn versions:display-plugin-updates
mvn versions:display-dependency-updates -U -ntp
mvn versions:display-plugin-updates -U -ntp
Loading

0 comments on commit 34a621f

Please sign in to comment.