Resolving Plugin Output Collision
Cucumber does not provide a native mechanism to enforce the sequential execution order of plugins or to isolate their output streams when both are targeting the standard output (stdout). Because plugins act as listeners to the same event bus, they trigger concurrently. If both the pretty and json plugins are configured to write to the console, their outputs will interleave, resulting in corrupted JSON and fragmented human-readable logs.
Likely Cause of Interleaving
The interleaving occurs when the json plugin is invoked without a specific file path (e.g., --plugin json instead of --plugin json:target/cucumber.json). In this scenario, both plugins compete for the stdout stream. The monochrome flag removes ANSI color codes but does not synchronize the write operations of separate plugins, meaning it cannot prevent interleaving.
Recommended Configuration Pattern
To obtain clear step-level alerts in the console while maintaining a clean JSON file for downstream reporting, you must isolate the JSON plugin to a physical file. This removes the JSON stream from the console entirely, leaving only the pretty output for human observation.
Use the following plugin configuration in your CLI or Runner class:
--plugin pretty --plugin json:target/cucumber-report.json
Verification Steps:
- Isolate Console: Run the suite with only
--plugin pretty. Confirm that step alerts are legible and not interrupted.
- Verify File Integrity: Run the suite with the dual configuration above. Open
target/cucumber-report.json to ensure it is a valid JSON array and not interleaved with "Scenario:" or "Given" text.
- Test CI Environment: Apply the
--monochrome flag to ensure the console logs remain clean of ANSI characters without affecting the JSON file content.
Assumptions and Constraints
- Version: This assumes Cucumber-JVM 7.x.
- Stream: It is assumed that "noise" refers to the JSON structure appearing in the console logs.
Diagnostic Detail Needed: Are you currently specifying a file path for the JSON plugin, or are you relying on the default stdout output for both?