[英]TestNG Re run test on failure, not running BeforeClass AfterClass methods
I implemented logic that re runs a failed TestNG test class from the following link: 我实现了从以下链接重新运行失败的TestNG测试类的逻辑:
https://martinholladay.wordpress.com/2013/11/17/webdriver-2-0-automatically-retry-failed-tests/ https://martinholladay.wordpress.com/2013/11/17/webdriver-2-0-automatically-retry-failed-tests/
Unfortunately, it runs the method with the "Test" annotation, and not running the BeforeClass (@BeforeClass) and AfterClass (@AfterClass) methods. 不幸的是,它运行带有“ Test”注释的方法,而不运行BeforeClass(@BeforeClass)和AfterClass(@AfterClass)方法。 I tried looking into setDependsOnMethods and getDependsOnMethods methods of ITestAnnotations to no avail.
我试图研究ITestAnnotations的setDependsOnMethods和getDependsOnMethods方法,但无济于事。
Does anybody know how to get the listener class to run BeforeClass and AfterClass methods as well? 有人知道如何让侦听器类也运行BeforeClass和AfterClass方法吗?
public class RetryListener implements IAnnotationTransformer {
public void transform(ITestAnnotation annotation, Class testClass,
Constructor testConstructor, Method testMethod) {
IRetryAnalyzer retry = annotation.getRetryAnalyzer();
if (retry == null) {
annotation.setRetryAnalyzer(Retry.class);
}
}
}
//The test begins here....
@BeforeClass(alwaysRun = true)
@Parameters("Environment")
public void BeforeClass(String sEnv) throws Exception {
WebDriver driver = new FirefoxDriver();
driver.get("www.google.com");
}
@Test
public void TestMethod() {
//Some test...
}
@AfterClass(alwaysRun = true)
public void AfterClass() {
driver.quit();
}
TestNG invokes only failed @Test
methods. TestNG仅调用失败的
@Test
方法。 You can see implementation here https://github.com/cbeust/testng/blob/master/src/main/java/org/testng/internal/Invoker.java#L1408 您可以在此处查看实现https://github.com/cbeust/testng/blob/master/src/main/java/org/testng/internal/Invoker.java#L1408
So no, you can't invoke @BeforeClass
and @AfterClass
in RetryListener again. 因此,不能,您不能再次在RetryListener中调用
@BeforeClass
和@AfterClass
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.