How to re-run your failed test cases in Cucumber with TestNG?
1. Add rerun:target/rerun.txt in your Cucumber plugin Option like:
plugin = {"rerun:target/rerun.txt" }
2. Once you execute you main Runner class it will create "rerun.txt" file in "target" folder which will have your failed test cases like:
OrderFlow 4:4
LoginFlow 21:21
3. You need to take this "rerun.txt" and bind it with features option of Cucumber in a new Runner class say "FailedScenarios" like:
features = "@target/rerun.txt"
Your TestRunner (Main) class will be like:
@CucumberOptions(
features = "src\\main\\java\\com\\qa\\feature",
glue = { "stepDefinitions" },
plugin = {
"com.cucumber.listener.ExtentCucumberFormatter:", "rerun:target/rerun.txt" },
monochrome = true,
strict = true,
dryRun = false,
tags = { "@Regression", "@Smoke" })
public class TestRunner extends AbstractTestNGCucumberTests {
@BeforeClass
public static void setupReportPath() {
Base.setupExtentReportPath();
}
@AfterClass
public static void writeExtentReport() {
Base.writeReport();
}
@AfterMethod
public void afterMethod(ITestResult iTestResult) throws IOException {
Base.statusAndScreenshot(iTestResult);
}
}
Your FailedScenarios (Runner) class will be like:
@CucumberOptions(monochrome = true, features = "@target/rerun.txt", // Cucumber picks the failed scenarios from this file
glue = { "stepDefinitions" }, plugin = {
"com.cucumber.listener.ExtentCucumberFormatter:" }, strict = true, dryRun = false)
public class FailedScenarios extends AbstractTestNGCucumberTests {
@BeforeClass
public static void setupReportPath() {
Base.setupExtentReportPath();
}
@AfterClass
public static void writeExtentReport() {
Base.writeReport();
}
@AfterMethod
public void afterMethod(ITestResult iTestResult) throws IOException {
Base.statusAndScreenshot(iTestResult);
}
}
Folder Structure:
Comments
Post a Comment