In vanilla Cucumber, anything output by a call to puts
in a step definition is captured as "test output" and formatted accordingly, as in the following output example:
Feature: A simple thing
Scenario: A simple scenario # features/simple.feature:3
Given I do a step # features/steps/step.rb:1
This text is output with puts
As you see above, it's helpfully indented in the "pretty" output format. In the JSON format, it's even captured in a structured way:
"keyword": "Scenario",
"name": "A simple scenario",
"line": 3,
"description": "",
"id": "a-simple-thing;a-simple-scenario",
"type": "scenario",
"steps": [
{
"keyword": "Given ",
"name": "I do a step",
"line": 4,
"output": [
"This text is output with puts"
],
}
],
The above is generated with a trivial feature file and a step definition like the following:
Given(/^I do a step$/) do
puts 'This text is output with puts'
end
Is there an equivalent function when implementing Cucumber steps in Java that I can use to have this output captured the same way? Printing to System.out
results in bypassing the capturing mechanism, much like using STDOUT.puts
in Ruby.
I haven't seen any Cucumber-JVM examples that make use of this feature, unlike many of Ruby Cucumber's examples, but there is clearly an entry in the JSON output by Cucumber-JVM for "output," and therefore I imagine there must be a way to write to that field.