Created
June 13, 2021 16:12
-
-
Save gsumit1/2df4efa7c7f3e6ab33682450ec5419c6 to your computer and use it in GitHub Desktop.
GetTestStepName.java -this class provides you the currently executing step name.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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