我的解决方案是为该方法中的所有方法设置一个retryAnalyzer@BeforeSuite
。但是不要在beforeMethod中设置它,因为这样每次调用时都会使用新的counter => endless loop重新创建它。
@BeforeSuite(alwaysRun = true)
public void beforeSuite(ITestContext context) {
TestRepeat testRepeat = new TestRepeat();
for (ITestNGMethod method : context.getAllTestMethods()) {
method.setRetryAnalyzer(testRepeat);
}
}