Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium, JAVA - error in @After

My @After function is:

  public void tearDown() throws Exception {
    driver.quit();
    String verificationErrorString = verificationErrors.toString();
    if (!"".equals(verificationErrorString)) {
      fail(verificationErrorString);
    }
  }

and when I run the test I get an error:

java.lang.AddesrtionError: java.langAssertionErrorjava.lang.AssertionError

at tear.Down, line:

      fail(verificationErrorString);

How to fix this one?

like image 833
k.horde Avatar asked Feb 23 '26 14:02

k.horde


1 Answers

It appears you are misunderstanding the purpose of Assert.fail(...) which is intended to cause a test to fail with the error message passed as a string. It does this by throwing an AssertionError. This is working as intended, its purpose is not failure logging.

I'm guessing that you want to report or log the verificationErrorString. If this is so then add the following to the top of your TestCase class.

Logger logger = LoggerFactory.getLogger(TestCase.class);

Then replace your fail(verificationErrorString) with some thing like

logger.warning(verificationErrorString);

or

logger.error(verificationErrorString);

However you could (should) just put those directly in the tests.

like image 200
Martin Spamer Avatar answered Feb 25 '26 02:02

Martin Spamer