Home > Enterprise >  Can't run individual Cucumber scenarios using TestNG test runner
Can't run individual Cucumber scenarios using TestNG test runner

Time:09-14

Is there anyway to run cucumber scenarios using the TestNG runner by right clicking individual scenarios in the feature files rather than using the command file or running the TestNG runner file directly?

I'm using Intellij to run cucumber scenarios in a maven testing framework. In the POM.xml file I have the Surefire plugin referencing the testNG.xml file which points to the TestNG runner class.

When I run "mvn test" from terminal it calls the TestNG testrunner,but when I right click on the scenario in the feature file to select run, it runs the io.cucumber.core.cli.main class that calls the io.cucumber.core.runner.Runner class testrunner.

I can't edit Run/Debug configuration to use the TestNG runner because the TestNG runner doesn't have a Main method.

CodePudding user response:

you can create a runner class and add tags you need into CucumberOptions.

@CucumberOptions(plugin = {"pretty"}, strict = true, tags = {"@yourTag"})
public class RunTestNGTest extends AbstractTestNGCucumberTests {
}

CodePudding user response:

If anybone runs into the same issue, I managed to get around the issue by creating another class with a main method and calling the mvn command to run the test from there. something like this:

String mvnCommand = "mvn test ";
ProcessBuilder processBuilder = new ProcessBuilder("cmd.exe", "/c", mvnCommand   args);
processBuilder.start();

Not sure if there's a better solution, but I can't seem to find any other option with Cucumber for Java plugin.

  • Related