'AfterScenario selenium Java did not work (API)

I have tried to add this tag @AfterScenario, my purpose here is after each scenario done, i want to get the test result(passed of fail) but this tags did not work for me

import net.serenitybdd.core.annotations.events.AfterScenario;

public class reportTest {

    @AfterScenario
    public void afterScenario(){
        System.out.println("hahahahhaha");
    }
}

enter image description here



Solution 1:[1]

maybe try using junit or testng for this hooks. Try changing the import and annotation.

junit :

import org.junit.BeforeClass
@BeforeClass
(your code)

testng :

import org.testng.annotations.BeforeClass;
@BeforeClass
(your code)

If you're using Cucumber and POM, import these from io.cucumber

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dharman