1

I am using cucumber-jvm + Junit + Maven to run my test cases . I could not able to find any methods to rerun my failed test cases . I have checked this Rerunning failed cucumber tests using cucumber-jvm . But the workaround does not working fine .

It would be good if you have any other way to rerun the test cases.

Community
  • 1
  • 1
sharan
  • 213
  • 9
  • 17
  • 1
    Possible duplicate of [Rerunning failed cucumber tests using cucumber-jvm](http://stackoverflow.com/questions/21334207/rerunning-failed-cucumber-tests-using-cucumber-jvm) – Sugat Mankar Dec 12 '16 at 11:57

2 Answers2

2

See the answer starting with "You can pass cucumber options to mvn as below" in Rerunning failed cucumber tests using cucumber-jvm

The following is copied from the above link based on asker's request

You can pass cucumber options to mvn as below

 mvn clean verify  -Dcucumber.options="@rerun.txt"

Note there is a tricky part here. If you are using the same test runner for both first run and rerun (and I believe that's what you want), then the test runner would contains something like

@CucumberOptions(plugin = { "rerun:target/rerun.txt"})

If you fire your rerun with maven using the same rerun file name as below

 mvn clean verify  -Dcucumber.options="@target/rerun.txt"

then cucumber will complain it could not find the rerun file. Why? Because the plugin "rerun:target/rerun.txt" will delete the file first with this test runner.

Workaround is copy/rename the file first, then kick off the mvn run like

mv target/rerun.txt rerun.txt &&  mvn clean verify  -Dcucumber.options="@rerun.txt"

And this is actually what you want. Because say if there are 5 failed scenarios in file target/rerun.txt. And with the rerun after some fix, 2 of them passed. Now the target/rerun.txt will contain the remaining 3 failed scenarios only, which would be your new start point along the debugging way.

Wenzhong Hu
  • 174
  • 1
  • 10
1

Use the rerun plugin to generate a list of scenarios that failed:

java cucumber.api.cli.Main --plugin rerun:rerun.txt features

This will write the location of each failing scenario to a text file called rerun.txt (you can call it whatever you want). Then you can use the output file as an input to your next run of Cucumber to specify which scenarios should be executed:

java cucumber.api.cli.Main < rerun.txt
Seb Rose
  • 3,628
  • 18
  • 29
  • When i run using "java cucumber.api.cli.Main --plugin rerun:rerun.txt features" , it throws error "Error: Could not find or load main class cucumber.api.cli.Main" .FYI , I am using Maven to run the test, "mvn test" . – sharan Apr 17 '15 at 10:36
  • Just use Maven as usual, but specify the rerun plugin in Cucumber Options – Seb Rose Apr 17 '15 at 12:23
  • 1
    To expand on my previous comment, take a look at https://groups.google.com/d/msg/cukes/BQ5sb7atomE/4sRu-CzhPC4J which shows use of the rerun plugin from Maven. Note that this is an old example and uses the deprecated 'format' option which has been replaced with the 'plugin' option. – Seb Rose Apr 17 '15 at 20:41
  • I have used your methods , but i have got the same error . I have run it using "mvn test -Dbrowser="ff" -Dcucumber.options="@rerun.txt"" . then i got , "java.lang.IllegalArgumentException: Not a file or directory: D:\Works\cucumber-junit\@rerun.txt" . Rerun is in my project path . so i changed to "mvn test -Dbrowser="ff" -Dcucumber.options="rerun.txt"" , then i got "cucumber.runtime.CucumberException: Error parsing feature file rerun.txt" . Please help me . – sharan Apr 21 '15 at 06:30
  • What folder is rerun.txt being generated in? – Seb Rose Apr 21 '15 at 06:38
  • It generated in project root path , not in target folder . – sharan Apr 21 '15 at 09:56