how to run failed scenarios in cucumber
Initially we have to add "<include>**/FailedRunner.java</include>"
into pom.xml configuration. Because maven-surefire-plugin decides which
runner class is able to run. Without adding into maven-surefire-plugin,
we cannot run any runner class automatically.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<runOrder>Alphabetical</runOrder>
<includes>
<include>**/CucumberRunner.java</include>
<include>**/FailedRunner.java</include> =======> This line
</includes>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
2. Then, add "rerun:target/rerun.txt" into @CucumberOptions
in CukesRunner class. So, we tell cucumber that you are going to
run if any test fails which is defined in target folder (rerun.txt).
@CucumberOptions(
features = "src/test/resources/features",
glue = "com/vytrack/step_definitions",
plugin = {"html:target/default-cucumber-reports",
"json:target/cucumber.json",
"rerun:target/rerun.txt" =======> This line
},
dryRun = false,
tags = "@smoke_test"
)
3. Create a new runner class as FailedRunner.
@CucumberOptions(
features = "@target/rerun.txt", ==> it will run only
those file which is failed scenarios.
glue = "com/vytrack/step_definitions",
plugin = {
"html:target/rerun-default-cucumber-reports", ==> it
will generate another report for failed scenarios
}
)
4. Create 'rerun.txt' file under target directory. ==> It may be
created automatically...
============================================================================
Rerunning A Failed Automated Test Automatically With Jenkins
What We’re Aiming for
- run a test
- check the status of the test result
- if the test result is a pass then end the run
- if the test results is a fail then try and run again
How we achieve this is by monitoring the Jenkins job console output
using the ‘Conditional Buildstep‘ plugin for Jenkins. The plugin allows
you to configure a job so that you search for a text string in the console
log and if you pick up a string that indicates a failure then you run
a conditional build step. That conditional build step is configured to
run the test a 2nd time. If it runs and passes on the 2nd attempt then
the overall build status is set to pass and you ignore the results from
the 1st attempt.