Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using TestNG @After annotation

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:

@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

If any could tell me what im doing wrong, because im clueless. I no each test works individually becuase i've tried it.

Thanks.

like image 670
elcharrua Avatar asked Sep 20 '13 19:09

elcharrua


People also ask

What is the use of @after in testing?

Analogous an @After annotated method gets executed after every @Test method. This can be used to repeatedly set up a Test setting and clean up after every test. So the tests are independent and preparation code is not copied inside the @Test method.

What is the use of @AfterTest annotation?

@AfterTest: A method with this annotation will be executed when all @Test annotated methods complete the execution of those classes inside the <test> tag in the TestNG. xml file. @BeforeSuite: It will run only once, before all tests in the suite are executed.


1 Answers

I think you might want to try @AfterMethod, instead of @AfterTest.

@AfterTest only runs once, after all of the @Test methods have run.

See the TestNG annotations documentation:

http://testng.org/doc/documentation-main.html#annotations

@AfterMethod: The annotated method will be run after each test method.

@AfterTest: The annotated method will be run after all the test methods belonging to the classes inside the tag have run.

Good Luck!

like image 144
Lori Johnson Avatar answered Sep 28 '22 05:09

Lori Johnson