com.codacy.scoobydoo.Retry Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scooby-doo-fwk Show documentation
Show all versions of scooby-doo-fwk Show documentation
Automated testing framework
package com.codacy.scoobydoo;
import org.testng.IRetryAnalyzer;
import org.testng.ITestResult;
public class Retry implements IRetryAnalyzer {
private final int maxTry;
private int count = 0;
public Retry() {
String retryEnvValue = System.getenv("RETRY_NUMBER");
if (retryEnvValue != null && !retryEnvValue.isBlank()) {
try {
maxTry = Integer.parseInt(retryEnvValue);
} catch (NumberFormatException e) {
final String errorMessage =
"Value [" + retryEnvValue + "] for key 'RETRY_NUMBER' is not valid. It as to be an integer.";
LoggingHelper.error(errorMessage, e);
throw e;
}
} else {
maxTry = 0;
}
}
@Override
public boolean retry(ITestResult result) {
if(result.isSuccess()) {
result.setStatus(ITestResult.SUCCESS);
return false;
} else if (hasShouldNotBeRetriedAnnotation(result)) {
return false;
} else {
if (count < maxTry) {
count++;
return true;
} else {
return false;
}
}
}
private boolean hasShouldNotBeRetriedAnnotation(ITestResult result) {
return result.getMethod().getConstructorOrMethod().getMethod().isAnnotationPresent(ShouldNotBeRetried.class);
}
}