public class ScreenshotOnFailureRule
extends org.junit.rules.TestWatcher
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 and Description |
|---|
ScreenshotOnFailureRule(HasDriver driverHolder)
Creates a new ScreenshotOnFailureRule in the provided test case.
|
ScreenshotOnFailureRule(HasDriver driverHolder,
boolean quitDriverOnFinish)
Creates a new ScreenshotOnFailureRule in the provided test case.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
failed(Throwable throwable,
org.junit.runner.Description description) |
protected void |
finished(org.junit.runner.Description description) |
protected File |
getErrorScreenshotFile(org.junit.runner.Description description) |
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.
|
public ScreenshotOnFailureRule(HasDriver driverHolder)
driverHolder - The HasDriver instance that holds the active WebDriver
instance. Commonly this is the TestBenchTestCase.public ScreenshotOnFailureRule(HasDriver driverHolder, boolean quitDriverOnFinish)
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.public void setQuitDriverOnFinish(boolean quitDriverOnFinish)
quitDriverOnFinish - true if the driver should be quit when a test has finished
running.protected void failed(Throwable throwable, org.junit.runner.Description description)
failed in class org.junit.rules.TestWatcherprotected void finished(org.junit.runner.Description description)
finished in class org.junit.rules.TestWatcherprotected File getErrorScreenshotFile(org.junit.runner.Description description)
description - test DescriptionCopyright © 2020-2021 Vaadin Ltd. All Rights Reserved.