Я хочу повторить тест Selenium, если тест не пройден из-за определенного типа Throwable.Для этого я использую IRetryAnalyzer.Это работает, и чтобы добавить это во время выполнения, я использую IAnnotationTransformer.
Однако @BeforeMethod не вызывается при повторной попытке, он говорит, что пропущена конфигурация.Я добавил (всегда Run = true).Можно ли также вызвать beforeMethod при повторной попытке?
Retry.java
public class Retry implements IRetryAnalyzer {
private final Map<String, Integer> testReRunMap = new HashMap<>();
private static int MAX_RETRY = 5;
@Override
public boolean retry(ITestResult iTestResult) {
System.out.println("Checking if test should be retried");
boolean shouldRetry = false;
//Compute shouldRetry
if (shouldRetry) {
return true;
} else {
return false;
}
}
}
AnnotationTransformer:
public class AnnotationTransformerListener implements IAnnotationTransformer {
@Override
public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor,
Method testMethod) {
annotation.setRetryAnalyzer(Retry.class);
}
}
BeforeMethod:
@BeforeMethod(alwaysRun = true)
public void beforeMethod() throws Exception {
//perform operation to be done before every test
}