0

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?

A.H
  • 23
  • 5
  • Your question is about TestNG soft asserts, which I gave a good answer to. Now you're changing your question and unaccepting and un-upvoting my answer. I don't really think that is fair to me so I will not be helping you any further. Good luck trying to get it working with assertj as they don't provide a hook like TestNG does.. – Mobrockers Jun 02 '16 at 06:23
  • Sorry about that you are absolutely right, I'm not used to ask on stak overflow I just look for weeks until I find something (me and my stupid pride :( ) but this time I have time limit. – A.H Jun 02 '16 at 06:33
  • I understand, thanks :) – Mobrockers Jun 02 '16 at 06:35

2 Answers2

0

You can use SoftAssert of implement IAssert on your own

Mrunal Gosar
  • 4,595
  • 13
  • 48
  • 71
  • But in soft assert I can onlt report once at the end, I want to report with the steps I have done so far – A.H Jun 01 '16 at 14:59
  • well there you go..go ahead and implement IAssert on your own then and feel free to play all with it :) – Mrunal Gosar Jun 02 '16 at 06:18
  • @MrunalGosar OP now no longer wants to use TestNG asserts for some reason so has no IAssert available anymore. – Mobrockers Jun 02 '16 at 06:21
0

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.

Mobrockers
  • 2,128
  • 1
  • 16
  • 28