I'm trying to us testng with fluentlenium, and report it to extent reports.
The problem is that I have asserts throughout the tests and want to report them without using try and catch.
Any ideas how to do it? Is there a assert listener or something?
What I did to do something like this ( I take screenshots on every assert failure ) is wrap the SoftAssert class like so:
import org.testng.asserts.IAssert;
public class SoftAssert extends org.testng.asserts.SoftAssert {
@Override
public void onAssertFailure(IAssert<?> assertCommand, AssertionError ex) {
LOGGER.log(Level.FATAL, assertCommand.getMessage());
//doReportingStuffHere
super.onAssertFailure(assertCommand, ex);
}
}
Now every time your soft assertion fails (while it happens, not just at the end) you can do your report stuff.