com.vaadin.testbench.

Class ScreenshotOnFailureExtension

java.lang.Object
com.vaadin.testbench.ScreenshotOnFailureExtension

All Implemented Interfaces:

org.junit.jupiter.api.extension.Extension, org.junit.jupiter.api.extension.TestWatcher

public class ScreenshotOnFailureExtension extends Object implements org.junit.jupiter.api.extension.TestWatcher

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

 
 public class MyTestCase extends TestBenchTestCaseJUnit5 {

      \@RegisterExtension public ScreenshotOnFailureExtension screenshotOnFailure = new ScreenshotOnFailureExtension(this, true);

      \@Test public void myTest() throws Exception {
          ...
      }
 }
 
 

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

  • Constructor Details

    • ScreenshotOnFailureExtension

      public ScreenshotOnFailureExtension(HasDriver driverHolder)

      Creates a new ScreenshotOnFailureExtension in the provided test case.

      Parameters:

      driverHolder - The HasDriver instance that holds the active WebDriver instance.

    • ScreenshotOnFailureExtension

      public ScreenshotOnFailureExtension(HasDriver driverHolder, boolean quitDriverOnFinish)

      Creates a new ScreenshotOnFailureExtension in the provided test case.

      Parameters:

      driverHolder - The HasDriver instance that holds the active WebDriver instance.

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

  • Method Details

    • setQuitDriverOnFinish

      public void setQuitDriverOnFinish(boolean quitDriverOnFinish)

      Tells the extension 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.

    • testFailed

      public void testFailed(org.junit.jupiter.api.extension.ExtensionContext context, Throwable cause)

      Specified by:

      testFailed in interface org.junit.jupiter.api.extension.TestWatcher

    • testSuccessful

      public void testSuccessful(org.junit.jupiter.api.extension.ExtensionContext context)

      Specified by:

      testSuccessful in interface org.junit.jupiter.api.extension.TestWatcher

    • getErrorScreenshotFile

      protected File getErrorScreenshotFile(org.junit.jupiter.api.extension.ExtensionContext context)

      Parameters:

      context - test ExtensionContext

      Returns:

      Failure screenshot file.