com.vaadin.testbench.

Class ScreenshotOnFailureRule

  • java.lang.Object
    • org.junit.rules.TestWatcher
      • com.vaadin.testbench.ScreenshotOnFailureRule
  • All Implemented Interfaces:

    org.junit.rules.TestRule


    public class ScreenshotOnFailureRule
    extends org.junit.rules.TestWatcher

    This JUnit Rule grabs a screenshot when a test fails. Usage:

     
     public class MyTestCase extends TestBenchTestCase {
    
          \@Rule public ScreenshotOnFailureRule screenshotOnFailure = new ScreenshotOnFailureRule(this, true);
    
          \@Test public void myTest() throws Exception {
              ...
          }
     }
     
     

    NOTE! Do NOT call driver.quit() in your tearDown() method (annotated with After). The tear down method will be run before this rule is run and if the driver is closed it is no longer possible to grab a screen shot of the situation.

    • Constructor Detail

      • ScreenshotOnFailureRule

        public ScreenshotOnFailureRule(HasDriver driverHolder)

        Creates a new ScreenshotOnFailureRule in the provided test case.

        Parameters:

        driverHolder - The HasDriver instance that holds the active WebDriver instance. Commonly this is the TestBenchTestCase.

      • ScreenshotOnFailureRule

        public ScreenshotOnFailureRule(HasDriver driverHolder,
                                       boolean quitDriverOnFinish)

        Creates a new ScreenshotOnFailureRule in the provided test case.

        Parameters:

        driverHolder - The HasDriver instance that holds the active WebDriver instance. Commonly this is the TestBenchTestCase.

        quitDriverOnFinish - Tells the rule whether to quit the driver when a single test has finished or not.

    • Method Detail

      • setQuitDriverOnFinish

        public void setQuitDriverOnFinish(boolean quitDriverOnFinish)

        Tells the rule whether to quit the driver when the test has finished executing or to allow the user to specify this.

        Parameters:

        quitDriverOnFinish - true if the driver should be quit when a test has finished running.

      • failed

        protected void failed(Throwable throwable,
                              org.junit.runner.Description description)

        Overrides:

        failed in class org.junit.rules.TestWatcher

      • finished

        protected void finished(org.junit.runner.Description description)

        Overrides:

        finished in class org.junit.rules.TestWatcher

      • getErrorScreenshotFile

        protected File getErrorScreenshotFile(org.junit.runner.Description description)

        Parameters:

        description - test Description

        Returns:

        Failure screenshot file.