com.vaadin.testbench.
Class ScreenshotOnFailureExtension
All Implemented Interfaces:
org.junit.jupiter.api.extension.Extension
, 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 Summary
ConstructorsConstructorDescriptionScreenshotOnFailureExtension
(HasDriver driverHolder) Creates a new ScreenshotOnFailureExtension in the provided test case.
ScreenshotOnFailureExtension
(HasDriver driverHolder, boolean quitDriverOnFinish) Creates a new ScreenshotOnFailureExtension in the provided test case.
-
Method Summary
Modifier and TypeMethodDescriptionprotected File
getErrorScreenshotFile
(org.junit.jupiter.api.extension.ExtensionContext context) 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.
void
testFailed
(org.junit.jupiter.api.extension.ExtensionContext context, Throwable cause) void
testSuccessful
(org.junit.jupiter.api.extension.ExtensionContext context) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.junit.jupiter.api.extension.TestWatcher
testAborted, testDisabled
-
Constructor Details
-
ScreenshotOnFailureExtension
Creates a new ScreenshotOnFailureExtension in the provided test case.
Parameters:
driverHolder
- TheHasDriver
instance that holds the active WebDriver instance. -
ScreenshotOnFailureExtension
Creates a new ScreenshotOnFailureExtension in the provided test case.
Parameters:
driverHolder
- TheHasDriver
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
Specified by:
testFailed
in interfaceorg.junit.jupiter.api.extension.TestWatcher
-
testSuccessful
public void testSuccessful(org.junit.jupiter.api.extension.ExtensionContext context) Specified by:
testSuccessful
in interfaceorg.junit.jupiter.api.extension.TestWatcher
-
getErrorScreenshotFile
Parameters:
context
- testExtensionContext
Returns:
Failure screenshot file.
-