Skip to content

Instantly share code, notes, and snippets.

@gsumit1
Created June 13, 2021 16:12
Show Gist options
  • Save gsumit1/2df4efa7c7f3e6ab33682450ec5419c6 to your computer and use it in GitHub Desktop.
Save gsumit1/2df4efa7c7f3e6ab33682450ec5419c6 to your computer and use it in GitHub Desktop.
GetTestStepName.java -this class provides you the currently executing step name.
package com.ctl.it.qa.sample.tests;
import cucumber.api.PickleStepTestStep;
import cucumber.api.event.ConcurrentEventListener;
import cucumber.api.event.EventHandler;
import cucumber.api.event.EventPublisher;
import cucumber.api.event.TestStepStarted;
public class GetTestStepName implements ConcurrentEventListener {
public static String currentStepName;
public EventHandler<TestStepStarted> stepHandler = new EventHandler<TestStepStarted>() {
@Override
public void receive(TestStepStarted event) {
handleTestStepStarted(event);
}
};
public void setEventPublisher(EventPublisher publisher) {
publisher.registerHandlerFor(TestStepStarted.class, stepHandler);
}
private void handleTestStepStarted(TestStepStarted event) {
if (event.testStep instanceof PickleStepTestStep) {
PickleStepTestStep testStep = (PickleStepTestStep)event.testStep;
currentStepName = testStep.getStepText();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment