我有一个自动化框架TestNG + Selenide,它可以在Jenkins上运行作业并提供Allure报告。我添加了一个测试类,其中包含一些简单的测试。当尝试单击某个元素时,一个测试偶尔会失败,但重新运行可以修复问题,所以很自然地,我想为这个测试引入重试。
问题来了-失败的测试不会重试。我尝试过通过注解转换器添加IRetryAnalyzer/RetryAnalyzerCount或将retryAnalyzer添加到@Test注解,但没有成功。
我的当前配置:
public class RetryAnalyzer extends RetryAnalyzerCount {
private static final int MAX_RETRY_ATTEMPTS = 3;
public RetryAnalyzer() {
setCount(MAX_RETRY_ATTEMPTS);
}
@Override
public boolean retryMethod(ITestResult iTestResult) {
return true;
}
}
public class AnnotationTransformer implements IAnnotationTransformer {
private final Logger logger = LoggerFactory.getLogger(AnnotationTransformer.class);
@Override
public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {
annotation.setRetryAnalyzer(RetryAnalyzer.class);
logger.debug("SET RETRY ANALYZER FOR TEST {}", testMethod.getName());
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="E2 widget tests" thread-count="6" parallel="classes" data-provider-thread-count="3">
<listeners>
<listener class-name="framework.AnnotationTransformer"/>
</listeners>
<test name="E2 widgets - chrome">
<parameter name="browser" value="chrome"/>
<parameter name="width" value="1366"/>
<parameter name="height" value="786"/>
<packages>
<package name="tests.other.e2widgets" />
</packages>
</test>
</suite>
我的测试+它正在使用的数据提供程序
@DataProvider(name = "countries-with-odds-widget-enabled", parallel = true)
public Object[][] countriesWithOddsWidgetEnabled() {
List<String> oddsWidgetCountries = sevWidgetSteps.getOddsWidgetCountries(configUrl);
List<Object[]> parameters = oddsWidgetCountries.stream().map(country -> new Object[]{country}).collect(Collectors.toList());
return parameters.toArray(new Object[1][parameters.size()]);
}
@Test(description = "Check odds widget for all countries",
dataProvider = "countries-with-odds-widget-enabled"
)
public void checkOddsWidgetsForEnabledCountries(String country) {
...some code...
// here test fails because of ElementClickInterceptedException
$(By.id("3__match-calendar-link")).click();
proxy.stop();
softly.assertAll();
}
我在诱惑报告中看到的错误:
Invalid element state [[id*='match-calendar-link'][3]]: element click intercepted: Element <a id="3__match-calendar-link" class="zh Eh">...</a> is not clickable at point (690, 296). Other element would receive the click: <div class="Mg"></div>
Screenshot: file:/Users/jenkins/workspace/UI-SANDBOX/build/reports/tests/1653409276041.25.png
Page source: file:/Users/jenkins/workspace/UI-SANDBOX/build/reports/tests/1653409276041.25.html
Timeout: 10 s.
Caused by: ElementClickInterceptedException: element click intercepted: Element <a id="3__match-calendar-link" class="zh Eh">...</a> is not clickable at point (690, 296). Other element would receive the click: <div class="Mg"></div>
我希望在单击方法失败的情况下重试测试,但在诱惑报告中我看不到任何重试,尽管如果方法在这一点上没有失败,但后来由于Assert,它将被重试。希望有人能帮助我解决这个问题,提前感谢
1条答案
按热度按时间qq24tv8q1#
如果没有maven surefire插件,请尝试将其添加到pom.xml中