I am using spring-boot cucumber with TestNG to write and API test framework ,
wanted to undersatand how can add tags and feature file to executed based on environment selected
Below is my current implementation
@CucumberOptions(
features = {"src/test/resources/Features"},
glue = {"als.system.tests.stepDefinations"},
plugin = {"pretty", "html:target/cucumber-html-report.html"}
)
public class CucumberRunnerTests extends AbstractTestNGCucumberTests {
}
And skipping test based on tags , but this is not ideal solution and also dont want to display skipped test on report
@Before
public void setup(Scenario scenario) {
if (!scenario.getSourceTagNames().contains("@" + productName.toLowerCase())) {
throw new SkipException("Skipping /Ignoring this scenario as not part of executions !!!");
}
}
Is there clean way to achieve this ?
Here's how you do it.
7.6.1as of today and it needs JDK11)com.rationaleemotions.TagBasedInterceptor<listener>tag (or) using the service provider interface approach. For details on this, you can refer to the official TestNG documentation here (or) refer to my blog-post here.Below is a sample implementation of the listener
Here's how the suite xml would look like
Below are the dependencies that I am using for this sample
Feel free to enhance the listener such that if it also reads from the JVM argument (which you can specify using
-D) so that you can have the dynamic behaviour of overriding the tag value in the suite xml with something that can be specified as a tag (or a comma separated list of tags) through the JVM argument.