[Cucumber-JVM]: Cucumber 4.x TestStepStarted, TestStepFinished events getting invoked at end of test

383 views
Skip to first unread message

Anukul Singhal

unread,
Jan 3, 2019, 6:23:12 PM1/3/19
to Cukes
Hi,

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


Gabor

unread,
Jan 25, 2019, 4:17:25 PM1/25/19
to Cukes
Is Cucumber still actively supported?

George Dinwiddie

unread,
Jan 25, 2019, 8:21:04 PM1/25/19
to cu...@googlegroups.com
Gabor,

On 1/23/19 3:28 PM, Gabor wrote:
> Is Cucumber still actively supported?

Very much so.

- George

--
----------------------------------------------------------------------
* George Dinwiddie * http://blog.gdinwiddie.com
Software Development http://www.idiacomputing.com
Consultant and Coach http://www.agilemaryland.org
----------------------------------------------------------------------

MP Korstanje

unread,
Mar 4, 2019, 11:02:08 AM3/4/19
to Cukes
This was covered in the release announcement:

https://cucumber.io/blog/announcing-cucumber-jvm-4-0-0/

Implementations of ConcurrentEventListener will receive events as they happen.

On Friday, January 4, 2019 at 12:23:12 AM UTC+1, Anukul Singhal wrote:
Reply all
Reply to author
Forward
0 new messages