I think you can override Cucumber's formatter with one of your own using the --format flag. The documentation is here. You may alternatively be able to add your own custom formatter when constructing the Cucumber options; this blog shows how. Relevant snippet:
@RunWith(Cucumber.class)
@CucumberOptions(
plugin = {"pretty",
"json:target/report.json",
"html:target/html",
"config.CustomTagsFormatter:target/tags.txt"},
features = "src/test/resources/feature")
public class TestRunner {}
You will have to do some clever programming to get the type of step, since Cucumber doesn't really differentiate between Given, When and Then. Take a look at what you get in the different events, though; the step_activated
event should give you the full text of the step, including the starting keyword.
Bear in mind that some of the steps may start with "And" or "But" rather than "Then", so it isn't as simple as counting all the "Then" steps. I suggest turning a counter on for "Then" at the start of a step, and turning it off if you encounter a "Given" or "When".
I'm very curious as to why you need this, though! Any step - even Givens or Whens - could theoretically contain an assertion that might fail, and Thens could contain more than one.