1

Am using retry analyzer and extent report for selenium project. When a test case is failed, using retry analyzer the failed test case is ran twice. Issue is in Extent report am able to see both the runs. One as Skiped and the other as Failed.

How to modify extent report , such that it will provide only test result of final run i.e only Failed should be reported.

Extent reoprt version - 2.41.2

Code:
Retry Analyzer:
public class RetryAnalyzer implements IRetryAnalyzer{
    int counter = 0;
    int retryLimit = 1;

    public boolean retry(ITestResult result){
        if(counter<retryLimit){
            counter++;
            return true;
        }
        return false;
    }

}

@BeforeMethod
    public void aSetup(Method method) {
        Report.loadConfig(new File(".\\Reports\\extent-config.xml"));
        logger = Report.startTest(method.getName());
    }

This images shows same test case, but i need only one to be logged

Sundar
  • 11
  • 3

2 Answers2

0

In the testLisener onTestFailure method you can check the counter and if the counter is 1 then do nothing else report.

@Override 
public void onFinish(ITestContext context) { 

Iterator<ITestResult> skippedTestCases = context.getSkippedTests().getAllResults().iterator(); 

while (skippedTestCases.hasNext()) { 
  ITestResult skippedTestCase = skippedTestCases.next(); 
  ITestNGMethod method = skippedTestCase.getMethod(); 
    if (context.getSkippedTests().getResults(method).size() > 0) { 
       skippedTestCases.remove(); 
       }
    }
 }
Abhishek_Mishra
  • 4,551
  • 4
  • 25
  • 38
Neagu V
  • 470
  • 4
  • 16
  • could you pls give an example. below code am using for removing skipped test cases, but in extent report still they are shown – Sundar Jul 25 '18 at 11:32
  • @Override public void onFinish(ITestContext context) { Iterator skippedTestCases = context.getSkippedTests().getAllResults().iterator(); while (skippedTestCases.hasNext()) { ITestResult skippedTestCase = skippedTestCases.next(); ITestNGMethod method = skippedTestCase.getMethod(); if (context.getSkippedTests().getResults(method).size() > 0) { skippedTestCases.remove(); } } } – – Sundar Jul 25 '18 at 11:45
0

the retried test will get skipped so testng has one parameter which will tell you that test is retried or not, Below snippet will help you i guess.

   if(result.getStatus() == ITestResult.SKIP) {
            if (result.wasRetried()) 
                extent.removeTest(extentReports);
            
        }