这样的junit:
@Test
public void testA {
//some code here...
}
@Test
pulic void testB {
//some code here...
}
@After
public void closeBrowsers() throws Exception {
selenium.stop();
}问题是:在每个测试方法之后调用closeBrowsers()方法;在这种情况下,它被调用两次,并且我得到了“错误的测试完成”。来自JUnit。我需要一个junit方法/注解,它将在所有测试完成后调用(只在所有测试完成后调用一次),这是可能的吗?
此外,我还尝试检查closeBrowsers()中是否启用了selenium,但我无法找到任何解决方案。
附言:我读过这个:How to close a browser on a selenium RC server which lost it's client
但是我不能理解解决方案,而且目前http://www.santiycr.com.ar/djangosite/blog/posts/2009/aug/25/close-remaining-browsers-from-selenium-rc博客端也停机了
发布于 2010-07-28 18:04:37
您可以将selenium变量设为静态变量,在@BeforeClass静态方法中对其进行初始化,并在@AfterClass中进行清理:
public class ...... {
private static Selenium selenium;
@BeforeClass
public static void initSelenium() {
selenium = new DefaultSelenium(...); // or initialize it in any other way
}
@Test
public void testA {...}
@Test
pulic void testB {...}
@AfterClass
public static void closeBrowsers() throws Exception {
selenium.stop();
}
}发布于 2010-07-27 22:35:36
使用@AfterClass注释。
http://junit.sourceforge.net/doc/faq/faq.htm#organize_3
https://stackoverflow.com/questions/3343979
复制相似问题