package test.template.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.ITestResult;
import org.testng.util.RetryAnalyzerCount;

/**
 * An implementation of IRetryAnalyzer that allows you to specify the maximum
 * number of times you want your test to be retried.
 */
public final class TestngRetry extends RetryAnalyzerCount {
	private Logger log = LoggerFactory.getLogger(this.getClass());

	public TestngRetry() {
		setCount(1);
	}

	@Override
	public boolean retryMethod(ITestResult result) {
		log.info("Retry...");
		return !result.isSuccess();
	}

}

@@ -21,17 +21,100 @@
 e.utils;
-%0A
+%0D%0A%0D%0Aimport java.util.ArrayList;%0D%0Aimport java.util.Arrays;%0D%0Aimport java.util.List;%0D%0A%0D
 %0Aimport 
@@ -130,16 +130,17 @@
 .Logger;
+%0D
 %0Aimport 
@@ -163,16 +163,17 @@
 Factory;
+%0D
 %0Aimport 
@@ -188,19 +188,23 @@
 ng.I
-TestResult;
+RetryAnalyzer;%0D
 %0Aimp
@@ -222,37 +222,28 @@
 tng.
-util.RetryAnalyzerCount;%0A
+ITestResult;%0D%0A%0D
 %0A/**
+%0D
 %0A * 
@@ -316,16 +316,17 @@
  maximum
+%0D
 %0A * numb
@@ -374,12 +374,14 @@
 ied.
+%0D
 %0A */
+%0D
 %0Apub
@@ -412,16 +412,20 @@
 try 
-extend
+implement
 s 
+I
 Retr
@@ -437,15 +437,11 @@
 yzer
-Count
  %7B
+%0D
 %0A%09pr
@@ -504,52 +504,77 @@
 ());
-%0A%0A%09public TestngRetry() %7B%0A%09%09setCount(1
+%0D%0A%0D%0A%09private List%3CObject%5B%5D%3E paramsHasRetried = new ArrayList%3C%3E(
 );
+%0D
 %0A%09
-%7D%0A
+%0D
 %0A%09@O
@@ -580,16 +580,17 @@
 Override
+%0D
 %0A%09public
@@ -607,14 +607,8 @@
 etry
-Method
 (ITe
@@ -629,65 +629,540 @@
 t) %7B
+%0D
 %0A%09%09
-log.info(%22Retry...%22
+//Failed and parameters has not retry.%0D%0A%09%09if (!result.isSuccess() && !hasRetried(result.getParameters())) %7B%0D%0A%09%09%09log.info(%22Retry method %5B%22 + result.getMethod().getMethodName() + %22%5D with parameters:%22%0D%0A%09%09%09%09%09+ Arrays.toString(result.getParameters())
 );
+%0D
 %0A%09%09
-return !result.isSuccess();%0A%09%7D%0A%0A%7D
+%09paramsHasRetried.add(result.getParameters());%0D%0A%09%09%09return true;%0D%0A%09%09%7D%0D%0A%09%09return false;%0D%0A%09%7D%0D%0A%0D%0A%09private boolean hasRetried(Object%5B%5D parameters) %7B%0D%0A%09%09for (Object%5B%5D p : paramsHasRetried) %7B%0D%0A%09%09%09if (Arrays.equals(p, parameters)) %7B%0D%0A%09%09%09%09return true;%0D%0A%09%09%09%7D%0D%0A%09%09%7D%0D%0A%09%09return false;%0D%0A%09%7D%0D%0A%0D%0A%7D%0D
 %0A

Update TestngRetry