we override ITestRunnerFactory (for maven surefire plugin to rerun the failed cases) and created custom TestRunner and override the run() method in TestRunner while using 7.4.0 version. while upgrading to 7.9.0, it is asking new parameter called suiteRunner. we don't know how to pass that information. I posted the code here. could you please help us to correct the code.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<suiteXmlFiles>
<suiteXmlFile>./src/test/resources/${test.suite}.xml</suiteXmlFile>
</suiteXmlFiles>
<forkMode>never</forkMode>
<properties>
<property>
<name>testrunfactory</name>
<value>com.xxx.cx.qe.core.extensions.testng.TestNGRunnerFactory</value>
</property>
</properties>
</configuration>
</plugin>
******************************************
public class TestNGRunnerFactory implements ITestRunnerFactory {
@Override
public TestRunner newTestRunner(ISuite iSuite, XmlTest xmlTest, Collection<IInvokedMethodListener> collection, List<IClassListener> list) {
IConfiguration configuration = new Configuration();
configuration.setObjectFactory(new DefaultTestObjectFactory());
SuiteRunner suiteRunner = (SuiteRunner) iSuite;
suiteRunner.setObjectFactory(configuration.getObjectFactory());
return new TestNGRunner(configuration,iSuite, xmlTest, xmlTest.skipFailedInvocationCounts(), collection, list,(ISuiteRunnerListener) iSuite);
}
}
**************************************************************
public class TestNGRunner extends TestRunner {
public TestNGRunner(IConfiguration configuration, ISuite suite, XmlTest test, boolean skipFailedInvocationCounts
, Collection<IInvokedMethodListener> invokedMethodListeners, List<IClassListener> classListeners,ISuiteRunnerListener suiteRunner) {
super(configuration, suite, test, skipFailedInvocationCounts, invokedMethodListeners, classListeners, suiteRunner);
}
@Override
public void run() {
RetryManager.getInstance().setCurrentReTry(0); // Need this to support multi suite TestNG XMLs.
super.run();
int retryCount = 3;
LoggerUtil.logINFO("Retry count set in system property 'failure.retry.count' : " + retryCount);
for (int i = 0; i < retryCount; i++) {
IResultMap failedTests = super.getFailedTests();
IResultMap skippedTests = super.getSkippedTests();
Collection<ITestNGMethod> failedMethods = failedTests.getAllMethods();
Collection<ITestNGMethod> skippedMethods = skippedTests.getAllMethods();
if (!failedMethods.isEmpty() || !skippedMethods.isEmpty()) {
// Set the current retry count to the retryManager instance
RetryManager.getInstance().setCurrentReTry(i + 1);
// Iterate each failed test and execute again.
FailedTestInterceptor failedTestInterceptor = new FailedTestInterceptor(failedMethods, skippedMethods);
super.addListener(failedTestInterceptor);
super.run();
}
else {
break;
}
}
}
}
************************************************************
public class RetryManager {
private static RetryManager retryManager;
private int retry = 0;
private RetryManager() {
}
// Return the retry manager instance
public static RetryManager getInstance() {
if (retryManager == null) {
retryManager = new RetryManager();
}
return retryManager;
}
public int getCurrentReTry() {
return this.retry;
}
public void setCurrentReTry(int currentCycle) {
this.retry = currentCycle;
}
/**
* This method is to check if there are remaining re-try attempts.
* Note that this method does not account the statuses of test results
* (ie: It simply says whether there are remaining retries if there are any failures at the end of current run)
*
* @return true if {@link RetryManager#getCurrentReTry()} is less than {@link CoreConstants#RETRY_COUNT}
*/
public boolean hasNext() {
return this.retry < 3
}
}
public class TestNGRetryAnalyzer implements IRetryAnalyzer {
private int count = 0;
public boolean retry(ITestResult result) {
int retryLimit = 3;
if (count < retryLimit) {
LoggerUtil.logINFO("Retrying test case: " + result.getMethod() + " [" + (count + 1)
+ " out of " + retryLimit + "]");
count++;
return true;
}
return false;
}
}
*****************
public class FailedTestInterceptor implements IMethodInterceptor {
private Collection<ITestNGMethod> failedTests;
private Collection<ITestNGMethod> skippedTests;
public FailedTestInterceptor(Collection<ITestNGMethod> failedTests, Collection<ITestNGMethod> skippedTests) {
this.failedTests = failedTests;
this.skippedTests = skippedTests;
}
@Override
public List<IMethodInstance> intercept(List<IMethodInstance> list, ITestContext iTestContext) {
List<IMethodInstance> result = new ArrayList<>();
filterMethods(failedTests, list, result);
filterMethods(skippedTests, list, result);
return result;
}
private void filterMethods(Collection<ITestNGMethod> methodCollection, List<IMethodInstance> list, List<IMethodInstance> result) {
for (ITestNGMethod testNGMethod : methodCollection) {
for (IMethodInstance method : list) {
if (method.getMethod().getMethodName().equals(testNGMethod.getMethodName())
&& method.getMethod().getRealClass().getCanonicalName().equals(testNGMethod.getRealClass().getCanonicalName())) {
result.add(method);
break;
}
}
}
}
}
********************
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-users/34d2f7b7-63c8-44b5-a426-261e7145a024n%40googlegroups.com.
@AfterSuite(alwaysRun = true)
public void afterSuitee(ITestContext iTestContext) {
System.out.println("inside afterSuite);
}
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-users/a375c134-e1a1-4eaf-a100-19903c11a75bn%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-users/c2608511-9e15-410c-ba15-9f750c82438en%40googlegroups.com.