Monochrome Output in Cucumber JVM
What Is Monochrome Output?
Monochrome Output is a Cucumber configuration option that controls how execution logs are displayed in the console. When enabled, Cucumber removes ANSI color codes and special formatting sequences so the console output appears as clean plain text. It is mostly a readability feature for terminals, IDE consoles, and CI/CD logs that do not handle colored output well.
In simple terms, monochrome output produces clean console logs without color formatting or escape sequences. It does not change scenario execution, step matching, reports, browser behavior, or performance. It only affects how the execution text appears in the console.
Why Is Monochrome Needed?
Cucumber prints execution details such as features, scenarios, steps, pass/fail status, and errors. Some consoles render colored output correctly. Others display raw ANSI escape sequences, which can make logs difficult to read. This is especially common in CI servers, older terminals, plain text log viewers, or build systems that capture console output without color support.
When monochrome mode is enabled, the same information is printed in a simpler form. The log becomes easier to scan when debugging failed scenarios. This is useful in Jenkins or similar tools where long console logs must be reviewed after a build failure.
Execution Flow
Monochrome affects only the output formatting layer. Cucumber executes scenarios normally, generates console output, checks whether monochrome is enabled, and removes ANSI formatting when required.
Execute Scenario
-> Generate Console Output
-> Check Monochrome Setting
-> Remove ANSI Formatting
-> Print Clean Console Output
Because monochrome does not affect the execution engine, it cannot fix undefined steps, broken hooks, missing feature files, failed assertions, or Selenium synchronization problems. It makes logs cleaner; it does not make tests pass.
Where Is Monochrome Configured?
In JUnit 4 and TestNG projects, monochrome is configured inside @CucumberOptions.
@CucumberOptions(
features = "src/test/resources/features",
glue = "stepdefinitions",
plugin = {"pretty", "html:target/report.html"},
monochrome = true
)
If not specified, Cucumber uses its default console formatting. In many older configurations, monochrome = true is added by default because clean logs are easier to share and troubleshoot.
Monochrome and JUnit 5
In modern JUnit Platform style projects, console formatting is generally managed differently than in older @CucumberOptions based projects. Teams using JUnit 5 should check the current Cucumber and build-tool configuration approach rather than assuming the same annotation option applies. The key concept remains: console rendering is an output concern, not a scenario execution concern.
If a JUnit 5 project has unreadable console output, review the IDE console, terminal, build plugin, CI log renderer, and Cucumber plugin configuration. The solution may be outside the runner class.
Monochrome with Pretty Output
Monochrome is often used with the pretty plugin. The pretty plugin improves the structure of console output. Monochrome removes unwanted formatting codes. Together, they create readable logs for local and CI execution.
@CucumberOptions(
plugin = {"pretty"},
monochrome = true
)
Pretty and monochrome are not the same thing. Pretty controls readability of the printed Cucumber execution text. Monochrome controls color and escape formatting. HTML, JSON, and JUnit XML reports are separate report outputs and are not made monochrome by this option.
What Monochrome Does Not Do
Monochrome does not generate reports. It does not make execution faster. It does not change feature files. It does not affect step definition matching. It does not remove failures. It does not change HTML report styling. It does not replace logging. It simply cleans the console output.
This matters because beginners sometimes expect configuration options to solve unrelated problems. If steps are undefined, fix glue configuration. If reports are missing, fix plugin configuration. If tests are flaky, fix synchronization, data, or framework design. Monochrome is only for console output readability.
Use in CI/CD
CI/CD systems often capture logs as plain text. ANSI formatting can appear as noisy characters in such logs. Enabling monochrome in older JUnit 4 or TestNG Cucumber projects helps keep Jenkins, Bamboo, TeamCity, or other pipeline logs easier to read. This is useful when a failure occurs and someone must review the console output quickly.
Even with monochrome enabled, teams should still generate proper reports. Console logs are helpful for immediate debugging, but HTML, JSON, and JUnit XML reports provide better execution summaries and artifacts. Monochrome complements reporting; it does not replace it.
Common Mistakes
One mistake is expecting monochrome to change HTML reports. It does not. Another mistake is expecting monochrome to fix execution problems. It cannot. A third mistake is thinking monochrome is a reporting plugin. It is not. A fourth mistake is ignoring unreadable CI logs and assuming everyone can mentally filter escape sequences. Clean logs are a small but practical part of maintainable automation.
Best Practices
Enable monochrome = true in JUnit 4 or TestNG projects when cleaner console output is desired. Combine it with the pretty plugin for readable local and CI logs. Use it especially where ANSI escape sequences clutter pipeline output. Do not rely on it to improve performance, generate reports, or change scenario behavior. For JUnit 5 projects, verify the current platform configuration approach.
Real-Time Example in a Runner
In many older Cucumber JVM frameworks, the runner includes feature path, glue path, plugin configuration, and monochrome output together. This makes the runner easy to read because the execution setup is visible in one place.
@RunWith(Cucumber.class)
@CucumberOptions(
features = "src/test/resources/features",
glue = {"stepdefinitions", "hooks"},
plugin = {
"pretty",
"html:target/cucumber-report.html",
"json:target/cucumber.json"
},
monochrome = true
)
public class SmokeRunner {
}
In this example, pretty structures the console output, HTML and JSON generate reports, and monochrome keeps the console output plain and clean. These settings work together, but each has a different job. If the report is missing, monochrome is not the problem. If the console shows unreadable color characters, monochrome may help.
When Monochrome Helps Most
Monochrome is most useful when logs are copied, archived, emailed, displayed in plain text, or viewed inside tools that do not support ANSI color rendering. It also helps when a team wants all execution logs to look consistent across Windows terminals, Linux shells, IDE consoles, and CI systems. The more places the logs are viewed, the more valuable plain output becomes.
It is less important when the terminal already renders colored output well and the team prefers color-coded logs. Some developers like color because it makes pass, fail, and skipped statuses easier to spot. Others prefer plain output because it is stable everywhere. This is a team preference, not a test correctness issue.
Monochrome and Debugging
Clean logs support debugging because they reduce noise. When a scenario fails, the tester needs to find the failed scenario, failed step, exception message, stack trace, and any relevant hook output. ANSI escape sequences can make those details harder to read in raw logs. Monochrome removes that distraction.
However, debugging still depends on good step names, meaningful assertions, useful screenshots, and clear error messages. Monochrome cannot make a vague failure useful. It only ensures the console text is not polluted with formatting characters.
Practical Troubleshooting
If CI logs show strange characters around scenario names or statuses, enable monochrome in JUnit 4 or TestNG projects and rerun the build. If nothing changes, verify that the runner being executed is the runner you edited. Large projects sometimes have multiple runners, and the CI job may use a different one. Also check whether the output comes from Cucumber or from another library.
If HTML reports look unchanged, that is expected. Monochrome does not style report files. If JSON or XML reports look unchanged, that is also expected. Monochrome affects console output only.
Interview-Ready Summary
Monochrome Output controls how Cucumber displays execution logs in the console. When enabled, it removes ANSI escape sequences and produces clean, plain-text output. It is configured with monochrome = true in @CucumberOptions for JUnit 4 and TestNG projects.
The golden rule is simple: monochrome improves console readability only. It does not change reports, execution speed, test behavior, or step matching. Use it with the pretty plugin when clean logs are important.