import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.testng.IResultMap; import org.testng.ITestContext; import org.testng.ITestResult; import org.testng.Reporter; import org.testng.TestListenerAdapter; import org.testng.ITestNGMethod; import org.testng.collections.Lists; import org.testng.collections.Objects; public class RetryTestListener extends TestListenerAdapter { private List<ITestNGMethod> m_allTestMethods = Collections.synchronizedList(Lists.<ITestNGMethod>newArrayList()); private List<ITestResult> m_passedTests = Collections.synchronizedList(Lists.<ITestResult>newArrayList()); private List<ITestResult> m_failedTests = Collections.synchronizedList(Lists.<ITestResult>newArrayList()); private List<ITestResult> m_skippedTests = Collections.synchronizedList(Lists.<ITestResult>newArrayList()); private List<ITestResult> m_failedButWSPerTests = Collections.synchronizedList(Lists.<ITestResult>newArrayList()); private List<ITestContext> m_testContexts= Collections.synchronizedList(new ArrayList<ITestContext>()); private List<ITestResult> m_failedConfs= Collections.synchronizedList(Lists.<ITestResult>newArrayList()); private List<ITestResult> m_skippedConfs= Collections.synchronizedList(Lists.<ITestResult>newArrayList()); private List<ITestResult> m_passedConfs= Collections.synchronizedList(Lists.<ITestResult>newArrayList()); public synchronized void onTestFailure(ITestResult arg0) { m_allTestMethods.add(arg0.getMethod()); m_failedTests.add(arg0); } @Override public void onFinish(ITestContext context) { for(int i=0;i<context.getAllTestMethods().length;i++){ System.out.println("~~~~~~~~~~"+context.getAllTestMethods()[i].getCurrentInvocationCount()); if(context.getAllTestMethods()[i].getCurrentInvocationCount()==2){ System.out.println("~~~~~~~~~~~~~~~~~"+context.getAllTestMethods()[i].getParameterInvocationCount()); System.out.println(context.getAllTestMethods()[i].ignoreMissingDependencies()); if (context.getFailedTests().getResults(context.getAllTestMethods()[i]).size() == 2 || context.getPassedTests().getResults(context.getAllTestMethods()[i]).size() == 1){ context.getFailedTests().removeResult(context.getAllTestMethods()[i]); } } } } ... } |