This is an example of my runner class.
@RunWith(Cucumber.class)
@CucumberOptions(
tags = "@tryout",
plugin = {"pretty",
"html:target/cucumber-report.html",
"json:target/cucumber-report.json"},
features = {"src/test/resources/features"},
glue = {"steps"}
)
public class RunCucumberTryoutTest {
}
What I want is to dynamicly set "cucumber-report" name. I have found this link: Create customize file report name in @CucumberOptions
The issue now is that below imports don't work any more.
import com.cucumber.listener.ExtentProperties;
import com.cucumber.listener.Reporter;
I tried this: Create customize file report name in @CucumberOptions , but it didn't work.
When configuring Cucumbers plugins, all values in an annotation (such as @CucumberOptions
) are constants. So you can not use any dynamic values there.
Likewise, properties must be configured before they're read. So you must set any environment properties before the test is ran. This makes System.setProperty
unreliable as you can not guarantee it will be invoked before Cucumber runs.
Cucumber also does not support place holders for dates.
But if you switch to JUnit 5 (with the cucumber-junit-platform-engine
) you could do this by configuring the cucumber.plugin
property in Maven and use maven.build.timestamp
property to set the time stamp.
For example:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.0</version>
<configuration>
<properties>
<configurationParameters>
cucumber.plugin=html:target/cucumber-${maven.build.timestamp}.html
</configurationParameters>
</properties>
</configuration>
</plugin>
When doing this, make sure not to set the plugin property elsewhere. Or be sure to understand the order in which properties are resolved.
Edit:
With JUnit 4 you can use Surefirs systemPropertyVariables
instead of configurationParameters
.