A.H
A.H

Reputation: 23

Testng report assert and continue test

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?

Upvotes: 0

Views: 1081

Answers (2)

Mobrockers
Mobrockers

Reputation: 2148

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.

Upvotes: 0

Mrunal Gosar
Mrunal Gosar

Reputation: 4683

You can use SoftAssert of implement IAssert on your own

Upvotes: 0

Related Questions