javawebdrivertestng

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.


Solution

  • 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:

    https://testng.org/annotations.html

    @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!