Extent report Feature is marked as failed when it's node test has been retried

127 views Asked by At

Test automation project that uses: Java, Maven, TestNG, Selenium WebDriver and Extent Reports

I have two runners, one for execution and another one for failed test executions from the first run. My first runner configured to write failed scenarios in .txt file and second runner will pick failed scenarios from this .txt file and start re-execution.

I have added both the runner classes into my TestNG.xml so that they will start execution one after the other automatically.

Execution part working fine, but after the execution my extent report is getting mixed up with all the scenarios executed with first runner class (Passed + Failed scenarios) and it also getting added with re-runned failed scenarios by second runner class.

I just want to make sure, if any failed scenario from first run get passed in re-run then it should show as passed in the report and previously added failed entry should get removed for the scenario.

Ref: Extent report test is marked as failed when it's node test has been retried

below are my runner classes:

First Runner:

    @CucumberOptions(features = "src/test/resources/testExecutable/Opportunity.feature",
        glue = {"testExecutable"},
        plugin = {"pretty", "json:target/cucumber.json",
        "com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:",
        "timeline:test-output-thread/", "rerun:target/failedScenarios.txt"},monochrome=true, publish =true)
        
    public class TestRunner extends AbstractTestNGCucumberTests {
    @Override
    @DataProvider(parallel = true)
      public Object[][] scenarios() {
        return super.scenarios();
      }
    }

Second Runner:

    @CucumberOptions(features =  "@target/failedScenarios.txt",
        glue = {"testExecutable"},
        plugin = {"pretty", "json:target/cucumber_rerun.json",                                                                                                                                                    "com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:",
       "timeline:test-output-thread/", "rerun:target/failedScenarios.txt"},
        monochrome = true,
        publish = true)
        
    public class TestRunnerFailedScenarios extends AbstractTestNGCucumberTests {
    @Override
    @DataProvider(parallel = true)
    public Object[][] scenarios() {
    System.out.println("############## RE-RUN STARTED #####################");
    return super.scenarios();
    }
    }

TestNG:

<suite name="Cucumber Parallel Suite" verbose="1">
    <test name="Cucumber Tests">
        <classes>
            <class name="testExecutable.TestRunner"/>
            <class name="testExecutable.TestRunnerFailedScenarios"/>
        </classes>
    </test>
    </suite>

I tried removing scenario if it is failed in first run by adding below lines:

    @After(order = 2)
    public void removeFailedScenarios(Scenario scenario) {
      if (scenario.isFailed()) {
        ExtentCucumberAdapter.getCurrentScenario().getExtent().getReport()
             .removeTest(ExtentCucumberAdapter.getCurrentScenario().getModel());

       }
    }

with this I am able to remove the duplicate results, failed scenario which got passed in ru-run will be added as Passed in the report and failed entry is getting removed. But Feature is still getting marked as Failed in the report.

I am struggling to set Feature as Passed if all the nodes are getting passed after re-run, could you please help me solving this?

0

There are 0 answers