I am trying to find out if there is an option to figure out the cucumber step currently getting executed, I am trying to perform certain action depending on the step name.>
If you are using cucumber-jvm version that is 5.6.0 or latest please follow below solution. since Reporter class is deprecated you have to implement ConcurrentEventListener and add this class to your TestRunner plugin section.
public class StepDetails implements ConcurrentEventListener {
public static String stepName;
public EventHandler stepHandler = new EventHandler() {
@Override
public void receive(TestStepStarted event) {
handleTestStepStarted(event);
}
};
@Override
public void setEventPublisher(EventPublisher publisher) {
publisher.registerHandlerFor(TestStepStarted.class, stepHandler);
}
private void handleTestStepStarted(TestStepStarted event) {
if (event.getTestStep() instanceof PickleStepTestStep) {
PickleStepTestStep testStep = (PickleStepTestStep)event.getTestStep();
stepName = testStep.getStep().getText();
}
}
}
later add this class to your plugin section of cucumberOptions of your runner file
@CucumberOptions(dryRun=false,plugin = {".StepDetails"})
you can get the stepname wherever you want just by calling the stepName variable
System.out.println(StepDetails.stepName);