25

I have multiple scenarios listed in a feature file and I need to run only a single failing scenario (for debugging purposes).

I have mentioned @tag before the scenario but while in Test Runner file when given this tag it is running entire feature file. Please help me out how to put it correctly.

TEST Runner file -

tags={"@Islamic_User_check"},
Frank Schmitt
  • 30,195
  • 12
  • 73
  • 107
Aditya
  • 457
  • 2
  • 8
  • 27

4 Answers4

34

If you want to run a specific scenario using cucumber you need to provide the line number the scenario starts on like:

cucumber features/test.feature:7

if you use the @ feature it should point to a txt file where the line number is still given.

Source: https://www.relishapp.com/cucumber/cucumber/docs/cli/run-specific-scenarios

Hope this helps

Runningriot
  • 723
  • 8
  • 16
  • 4
    This works from Maven as well, something like: `mvn -D cucumber.options="src/test/resources/features/test.feature:7" verify`. – SiKing Nov 28 '18 at 00:42
  • 1
    Although this works, it is a very brittle approach, as any line shifting modification in the feature file will break this. Using tags, is a much more reliable approach. – fduff Jan 13 '21 at 15:53
  • 1
    Agree that it's brittle but sometimes I find myself not wanting to add a tag to a scenario just so that I can run it for debug purposes. Also, the line number doesn't have to be where the scenario starts - it can point to any step in the scenario and it will run the whole scenario. – Joman68 Dec 01 '21 at 03:04
23

Update: there is now a tags options

cucumber --tags @tagname

In maven:

 mvn test -Dcucumber.options="--tags @tagname"

(and in Windows powershell escape the -D with a backtick)

 mvn test `-Dcucumber.options="--tags @tagname"
JohnP2
  • 1,899
  • 19
  • 17
16

If you use IntelliJ then I suggest installing the Cucumber for Java plugin.

enter image description here

Then you can right-click on the Test annotation in the feature file and run that single test scenario.

enter image description here

javaPlease42
  • 4,699
  • 7
  • 36
  • 65
4

Use the --name REGEXP command line argument to run only the scenarios that match the regular expression REGEXP:

cucumber --name "Islamic_User_check"
Aweston
  • 379
  • 2
  • 10