Jadala Ajay
2 min readJun 26, 2021
  • Running/overriding Cucumber Options from maven command line

Last week I have posted running Automation tests from command line which is integrated with TestNG.

Now let us see how we can run/override the cucumber options from command line. We may use these commands while building Jenkins pipelines.

Assumptions:

  1. We have cucumber runner file with Junit.
  2. Framework is built using Maven build tool
  3. Cucumber and junit dependencies are configured in pom.xml

In general mvn test from project root directory where pom.xml is present runs Cucumber Features using Cucumber’s JUnit Runner.
The @RunWith (Cucumber.class) annotation on the TestRunner class tells JUnit to kick off Cucumber.

Cucumber run time parses the command-line options to know what Feature to run, where the Glue Code lives, what plugins to use, and so on.

On the other hand, if you run test from eclipse when you use the JUnit Runner, these options are generated from the @CucumberOptions annotation on your test.

Overriding Cucumber Options:

mvn test -DCucumber.options= “Your Options”
mvn test -Dcucumber.options=“-help”

This gives you the list of parameters that can be passed through command line using CucumberOptions.

Running a single Scenario from a specific feature file through Command Line:

If we want to run single Scenario from the cmd, we have to specify like below.

mvn test -Dcucumber.options=“feature file path” + “line number of the scenario”
Ex: mvn test -Dcucumber.options=src/test/resources/funcitonalTests/End2EndTest.feature:5"

Running Scenarios using Tags from Command Line:
If you want to run the test cases associated to Tags, this is how we specify :

mvn test -Dcucumber.options=“--tags @tag Name”
ex: mvn test -Dcucumber.options=“--tags @Smoke”

There is one more way to do this:

mvn test -Dcucumber.filter.tags=“@Smoke”

Overriding Report Plugin and Path:
If we want to generate a different report or if we wish to change the report path. This how we can do it:

mvn test -Dcucumber.options=“- -plugin junit:target/cucumber-reports/report.xml”

Running a specific Feature file only from Command Line:
If you want cucumber to run just a single feature file or multiple feature file, you can pass parameter for the same from command line. This how you do it:

mvn test -Dcucumber.options=“src/test/resources/functionalTests/End2End_Tests.feature”

Passing multiple Parameter at once:
Its also possible to pass multiple options at once.
This is how it can be done

mvn test -Dcucumber.options=“SomeThing” -Dcucumber.options=”SomeThing” -Dcucumber.options=“SomeThing”

Ex:mvn test -Dcucumber.options=“src/test/resources/functionalTests/End2End_Tests.feature” -Dcucumber.options=“- -tags @Smoke

or

mvn test -Dcucumber.options=“src/test/resources/functionalTests/End2End_Tests.feature” -Dcucumber.filter.tags=“@Smoke”

Hope this is useful. Happy Learning!!

Please comment for any improvements/corrections. Thanks.

Jadala Ajay
Jadala Ajay

Written by Jadala Ajay

8 Years Exp Senior Automation Engineer with expertise on Selenium,RestAsured API,Postman,Cypress,WebdriverIO with prog languages Java,Javascript and Python

No responses yet