Dhussein
Dhussein

Reputation: 29

How to run a Cucumber-JVM feature file from the command line

I have a file with file extension .feature. HOw do run this from the command line?

In order to make a batch file for each feature. I am using Cucumber-JVM with Java and Selenium.

Upvotes: 1

Views: 7593

Answers (3)

orcunbalcilar
orcunbalcilar

Reputation: 11

You can run any test runner or override default test runner by using the command line below. This means you only want to run the test named SmokeTestRunner. By the way, you are free to set surefire plugin in your pom.xml any way. For example, you can set up your surefire plugin in your pom.xml to run the regression test named RegressionTestRunner. It doesn't matter.

mvn -Dtest=**/SmokeTestRunner.java test

Your SmokeTestRunner java file should look like this. ->

@CucumberOptions(
features = "src/test/resources/features/Smoke.feature",
glue = {"stepdefinitions", "hooks"},
tags = "@chrome", // It runs only scenarios tagged with "@chrome"
plugin = {"pretty"/*you can add more cucumber plugins here if you want.*/},
monochrome = true)
public class SmokeTestRunner extends AbstractTestNGCucumberTests {}

For more details, have a look at the maven surefire plugin docs. (https://maven.apache.org/surefire/maven-surefire-plugin/examples/single-test.html)

Upvotes: 0

Uttej Guduru
Uttej Guduru

Reputation: 40

If you are using Maven, you can run your .feature file this way:

mvn -Dcucumber.options="from/the/root/of/module/to/the/feature/MyFeature.feature" test

This will override the @CucumberOptions in the test runner class.

Upvotes: 1

Reimeus
Reimeus

Reputation: 159844

Cucumber-JVM is based on JUnit so its just like running any unit tests from the command line

java -cp /path/to/junit.jar org.junit.runner.JUnitCore [test class name]

where test class name is annotated with @CucumberOptions whose features refer to the feature file. If youre using Maven you could use

mvn test

Upvotes: 3

Related Questions