cucumber-jvm does not provide an easy way to get the feature name, scenario name or the step that is being executed. I had to find a workaround for this. For reference it is listed here. I am using the mirage project that I created a while back that provides a few utility classes around reflection. The ReflectionUtils.getFieldInObject uses that.
I created an aspect and weaved the info.cukes:cucumber-junit jar file with the aspect.
This aspect is weaved into the cucumber-junit by doing this:
I created an aspect and weaved the info.cukes:cucumber-junit jar file with the aspect.
public aspect ReportFeatureScenarioStep {
pointcut running_feature() : execution(public * cucumber.junit.FeatureRunner.run(..));
pointcut running_scenario() : execution(public * cucumber.junit.ExecutionUnitRunner.run(..));
pointcut running_step() : execution(public * cucumber.junit.JUnitReporter.match(..));
// Not used. These are here for reference only
// pointcut completing_feature() : execution(public * cucumber.junit.FeatureRunner.run(..));
// pointcut completing_scenario() : execution(public * cucumber.junit.ExecutionUnitRunner.run(..));
// pointcut completing_step() : execution(public * cucumber.junit.JUnitReporter.result(..));
before() : running_feature() {
ParentRunner pr = (ParentRunner) thisJoinPoint.getTarget();
System.out.println(pr.getDescription().toString());
}
before() : running_scenario() {
ParentRunner pr = (ParentRunner) thisJoinPoint.getTarget();
System.out.println(pr.getDescription().toString());
}
before() : running_step() {
StepDefinitionMatch m = (StepDefinitionMatch) thisJoinPoint.getArgs()[0];
Step step = (Step) ReflectionUtils.getFieldInObject(m, "step");
System.out.println(step.getKeyword() + " " + m.getStepName());
}
// Not used. These are here for reference only
// after() : completing_feature() {
// ParentRunner pr = (ParentRunner) thisJoinPoint.getTarget();
// System.out.println("AFTER FEATURE : -->" + pr.getDescription() + "<--");
// }
//
// after() : completing_scenario() {
// ParentRunner pr = (ParentRunner) thisJoinPoint.getTarget();
// System.out.println("AFTER SCENARIO : -->" + pr.getDescription() + "<--");
// }
//
// after() : completing_step() {
// System.out.println("AFTER STEP ");
// }
}
This aspect is weaved into the cucumber-junit by doing this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<source>1.6</source>
<complianceLevel>1.6</complianceLevel>
<verbose>false</verbose>
<showWeaveInfo>false</showWeaveInfo>
<target>1.6</target>
<weaveDependencies>
<weaveDependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
</weaveDependency>
<weaveDependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
</weaveDependency>
</weaveDependencies>
</configuration>
</plugin>