I have recently switched from cucumber 3.0.2 to cucumber 4.2.0 (updated maven dependencies for cucumber-java, cucumber-testng and cucumber-picocontainer). I had written a CustomFormatter class which was implementing the Formatter interface in 3.0.2, have updated to use EventListener. When I execute the same test in 4.2.0, the TestStepStarted and TestStepFinished events are called at the very last of test run, and hence my custom reports are not forming in the order in which they should. Here is the snippet of my CustomFormatter class:
public class CustomFormatter implements EventListener {
...
...
@Override
public void setEventPublisher(EventPublisher publisher) {
publisher.registerHandlerFor(TestStepStarted.class, stepStartedHandler);
publisher.registerHandlerFor(TestStepFinished.class, stepFinishedHandler);
}
private void handleTestStepStarted(TestStepStarted event) { LOGGER.info("TEST STEP STARTED : " + testStep.getStepText());
...
...
}
private void handleTestStepFinished(TestStepFinished event) { LOGGER.info("TEST STEP FINISHED : " + testStep.getStepText()); ...
...
}
This formatter has been used in cucumber options as following:
@CucumberOptions(features = {"src/main/java/com/project/cucumber/features"},
glue = {"com.project.cucumber.stepdefs"},
plugin = {"com.sabre.cucumber.events.CustomFormatter"},
tags = {"@sampledemo"})
With 3.0.2, I had the same implementation, and the order of logging was this (I am using TestNGCucumberRunner):
TestNG @Test annotation -> Hooks (beforeScenario) -> CustomFormatter (TestStepStarted Event) -> Gherkin step execution -> Custom Formatter (TestStepFinished event) -> Hooks (afterScenario) -> TestNG @AfterClass
The above order was perfectly fine.
After updating to 4.2.0, the same test run is performing the following order:
TestNG @Test annotation -> Hooks (beforeScenario) -> Gherkin step execution -> Hooks (afterScenario) -> CustomFormatter (TestStepStarted Event for all test steps) -> Custom Formatter (TestStepFinished event for all test steps) -> TestNG @AfterClass
Is there some setting I am missing here that I need to keep in mind with 4.2.0? This is blocking me to migrate my tests from 3.x to 4.x. Kindly let me know if there is any other information you need.
Thanks,
Anukul