How to capture STDOUT in JCM Cucumber, like Cucumber Ruby?

In a vanilla cucumber, everything that is called by a call putsin the step definition is written as a "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, this is useful formatted in a β€œgood” output format. In JSON format, it is even written 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 file is generated using a trivial function file and step definition, as shown below:

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 get this output in the same way? Printing on System.outbypasses the capture mechanism, which is similar to using it STDOUT.putsin Ruby.

Cucumber-JVM, , Ruby Cucumber, JSON Cucumber-JVM "", .

+4
1

, , .

public class StepDefs {
  private Scenario scenario;

  /* Need to capture the scenario object in the instance to access it
   * in the step definition methods. */
  @Before
  public void before(Scenario scenario) {
    this.scenario = scenario;
  }

  @Given("^I do a step$")
  public void iDoAStep() {
    scenario.write("This text is output with scenario.write");
  }
}

puts Ruby, JSON. "" , , Ruby. , , .

+3

Source: https://habr.com/ru/post/1619097/


All Articles