Class JavascriptAlert

  • All Implemented Interfaces:
    org.junit.rules.TestRule

    public class JavascriptAlert
    extends TestFailureAwareRule
    Adds the text of a possible alert to the normal test failure as suppressed exception. The reason is that if an alert happens, there is usually a timeout from a WebDriver.findElement(By) call, which is caused actually by the alert which hangs the javascript processing. Alerts are unfortunately not visible on screenshots, they do not result in javascript console or webdriver log entries. So the only possibility to get this information is to try to fetch a possible alert message. This helps then the investigation.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void onError​(org.junit.runner.Description description, java.lang.Throwable testFailure)
      Called if the test has thrown an error.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JavascriptAlert

        public JavascriptAlert​(SeleniumProvider seleniumProvider)
    • Method Detail

      • onError

        protected void onError​(org.junit.runner.Description description,
                               java.lang.Throwable testFailure)
                        throws java.lang.Throwable
        Description copied from class: TestFailureAwareRule
        Called if the test has thrown an error. By default it does nothing.
        Overrides:
        onError in class TestFailureAwareRule
        Parameters:
        description - junit test description object
        testFailure - any error from the test
        Throws:
        java.lang.Throwable - this will be added to testFailure as suppressed exception. See Throwable.addSuppressed(Throwable)