Java 使用 TestNG @After 注释
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18924820/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using TestNG @After annotation
提问by elcharrua
I am automating a web page, and in a class I have several tests and when i run them through testng all of them the @Aftertest isn′t being invoked so the only test that works is the first one, because when the first test finished, it doens't call the aftertest to close the driver instance and start a new one. There are my methods:
我正在自动化一个网页,在一个类中我有几个测试,当我通过 testng 运行它们时,@Aftertest 没有被调用,所以唯一有效的测试是第一个,因为当第一个测试完成时,它不会调用 aftertest 来关闭驱动程序实例并启动一个新的实例。有我的方法:
@BeforeSuite
public void printInfo() {
Utilidades.addInformationTest();
}
@BeforeTest
public void loggerUser() throws Exception {
initializeSelenium("VerificacionUI_FraudMonitor_Issuer");
Utilidades.printInfo("Cargando datos de variables.");
setCMSModulo(modulo);
setUsuario(usuario);
setContrase?a(contrase?a);
startAccess();
parentWindowHandle = driver.getWindowHandle();
}
@AfterTest
public void shutDownSelenium() {
driver.quit();
}
and then come all of my six @Test
然后来我所有的六个@Test
If any could tell me what im doing wrong, because im clueless. I no each test works individually becuase i've tried it.
如果有人可以告诉我我做错了什么,因为我一无所知。我没有每个测试单独工作,因为我已经尝试过了。
Thanks.
谢谢。
采纳答案by Lori Johnson
I think you might want to try @AfterMethod, instead of @AfterTest.
我想你可能想尝试@AfterMethod,而不是@AfterTest。
@AfterTest only runs once, after all of the @Test methods have run.
@AfterTest 只运行一次,在所有 @Test 方法都运行之后。
See the TestNG annotations documentation:
请参阅 TestNG 注释文档:
http://testng.org/doc/documentation-main.html#annotations
http://testng.org/doc/documentation-main.html#annotations
@AfterMethod: The annotated method will be run after each test method.
@AfterMethod:注释的方法将在每个测试方法之后运行。
@AfterTest: The annotated method will be run after all the test methods belonging to the classes inside the tag have run.
@AfterTest:注释的方法将在属于标签内的类的所有测试方法都运行后运行。
Good Luck!
祝你好运!