Package 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 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 FilegetErrorScreenshotFile(org.junit.jupiter.api.extension.ExtensionContext context) voidsetQuitDriverOnFinish(boolean quitDriverOnFinish) Tells the extension whether to quit the driver when the test has finished executing or to allow the user to specify this.voidtestFailed(org.junit.jupiter.api.extension.ExtensionContext context, Throwable cause) voidtestSuccessful(org.junit.jupiter.api.extension.ExtensionContext context) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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- TheHasDriverinstance that holds the active WebDriver instance.
-
ScreenshotOnFailureExtension
Creates a new ScreenshotOnFailureExtension in the provided test case.- Parameters:
driverHolder- TheHasDriverinstance 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:
testFailedin interfaceorg.junit.jupiter.api.extension.TestWatcher
-
testSuccessful
public void testSuccessful(org.junit.jupiter.api.extension.ExtensionContext context) - Specified by:
testSuccessfulin interfaceorg.junit.jupiter.api.extension.TestWatcher
-
getErrorScreenshotFile
- Parameters:
context- testExtensionContext- Returns:
- Failure screenshot file.
-