A reporter that prints step-by-step progress to the console, mimicking testthat::ProgressReporter but with visibility into individual Gherkin steps.
Details
Prints each step as it executes with a status indicator, grouped under scenario and feature headers similar to testthat's output:
✓ for passed steps (green)
✗ for failed/errored steps (red)
Feature: Addition
Scenario: Add two numbers
✓ Given I have entered 50 into the calculator
✓ Given I have entered 70 into the calculator
✓ When I press add
✓ Then the result should be 120 on the screenUsage
Pass a reporter instance to test() or run():
# Step-level detail
cucumber::test("tests/acceptance", reporter = cucumber::CucumberProgressReporter$new())
# testthat reporters still work, reporting at the scenario level only
cucumber::test("tests/acceptance", reporter = testthat::ProgressReporter$new())
# Silent mode
cucumber::test("tests/acceptance", reporter = testthat::SilentReporter$new())
# From within a test file
cucumber::run(reporter = cucumber::CucumberProgressReporter$new())Creating custom reporters
Extend CucumberReporter to build your own:
HTMLReporter <- R6::R6Class(
"HTMLReporter",
inherit = cucumber::CucumberReporter,
public = list(
html_output = character(),
start_feature = function(feature_name) {
super$start_feature(feature_name)
self$html_output <- c(self$html_output, sprintf("<h2>%s</h2>", feature_name))
},
end_step = function(step) {
super$end_step(step)
status_class <- step$status %||% "passed"
self$html_output <- c(
self$html_output,
sprintf('<div class="step %s">%s %s</div>', status_class, step$keyword, step$text)
)
},
end_reporter = function() {
if (!is.null(super$end_reporter)) super$end_reporter()
writeLines(self$html_output, "test-report.html")
}
)
)Step metadata
When end_step() is called, the step object contains:
keyword- The step keyword (Given, When, Then, etc.)text- The step textstatus- One of "passed", "failed", or "error"error- The error object if the step failed or errored (NULL otherwise)duration- Execution time in secondsdata_table- Data table if present (NULL otherwise)docstring- Docstring if present (NULL otherwise)
Super classes
testthat::Reporter -> cucumber::CucumberReporter -> CucumberProgressReporter
Public fields
show_praiseWhether to show praise messages
step_countNumber of steps executed
step_passedNumber of steps that passed
step_failedNumber of steps that failed
current_scenarioName of the scenario currently executing
current_stepsSteps executed so far in the current scenario
failuresRecorded failures for the end-of-run summary
step_erroredWhether end_step already rendered an error this scenario
num_colorsTerminal color support captured at construction
reporter_max_docstring_linesMax docstring lines to print per step
reporter_max_table_linesMax data table rows to print per step
Methods
Inherited methods
testthat::Reporter$.start_context()testthat::Reporter$cat_line()testthat::Reporter$cat_tight()testthat::Reporter$end_context()testthat::Reporter$end_context_if_started()testthat::Reporter$end_file()testthat::Reporter$end_test()testthat::Reporter$is_full()testthat::Reporter$local_user_output()testthat::Reporter$rule()testthat::Reporter$start_context()testthat::Reporter$start_file()testthat::Reporter$start_reporter()testthat::Reporter$update()
Method new()
Initialize the reporter
Usage
CucumberProgressReporter$new(
show_praise = TRUE,
reporter_max_docstring_lines = getOption("cucumber.reporter_max_docstring_lines", Inf),
reporter_max_table_lines = getOption("cucumber.reporter_max_table_lines", Inf),
...
)Arguments
show_praiseWhether to show praise (default TRUE)
reporter_max_docstring_linesMax docstring lines to print for a step before truncating. Defaults to the
cucumber.reporter_max_docstring_linesoption, orInf(print in full) if unset.reporter_max_table_linesMax data table rows to print for a step before truncating. Defaults to the
cucumber.reporter_max_table_linesoption, orInf(print in full) if unset....Additional arguments passed to parent
Method print_step_args()
Print a step's docstring and/or data table arguments, indented and
truncated to reporter_max_docstring_lines / reporter_max_table_lines
