Run only a certain scenario using maven

15 views Asked by At

i have 2 scenarios in my feature file and i need to run only 1 scenario, can you please suggest me some mvn test command to do it

if i do :

mvn test -Dcucumber.options="src\test\resources\features\login.feature:9"

it is running both the scenarios, but i need to run only 1 scenarion which is in line 9

This is my feature file : login.feature


  Scenario: Check login with valid credentials
    Given user is on login page
    When user enters valid username and password
    And clicks on login button
    Then user is navigated to the home page

  Scenario: Check login with invalid credentials
    Given user is on login page
    When user enters invalid username and password
    And clicks on login button
    Then error message is displayed - Invalid Credentials
1

There are 1 answers

0
M.P. Korstanje On

Assuming you're on windows and using cucumber-junit you would use:

mvn test -D"cucumber.features=src\test\resources\features\login.feature:9" 

The quotes start after the -D because that's just how Windows does qoutes.

For the cucumber-junit-platform-engine use:

mvn test -D"surefire.includeJUnit5Engines=cucumber" -D"cucumber.plugin=pretty" -D"cucumber.features=src\test\resources\features\login.feature:9" 

Also note that cucumber.options doesn't exist anymore. For the latest properties see https://github.com/cucumber/cucumber-jvm/tree/main/cucumber-core#properties-environment-variables-system-options