com.vaadin.testbench.
Class ScreenshotOnFailureRule
All Implemented Interfaces:
org.junit.rules.TestRule
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 Summary
ConstructorsConstructorDescriptionScreenshotOnFailureRule
(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.
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
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.
Methods inherited from class org.junit.rules.TestWatcher
apply, skipped, skipped, starting, succeeded
-
Constructor Details
-
ScreenshotOnFailureRule
Creates a new ScreenshotOnFailureRule in the provided test case.
Parameters:
driverHolder
- TheHasDriver
instance that holds the active WebDriver instance. Commonly this is theTestBenchTestCase
. -
ScreenshotOnFailureRule
Creates a new ScreenshotOnFailureRule in the provided test case.
Parameters:
driverHolder
- TheHasDriver
instance that holds the active WebDriver instance. Commonly this is theTestBenchTestCase
.quitDriverOnFinish
- Tells the rule whether to quit the driver when a single test has finished or not.
-
-
Method Details
-
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
Overrides:
failed
in classorg.junit.rules.TestWatcher
-
finished
protected void finished(org.junit.runner.Description description) Overrides:
finished
in classorg.junit.rules.TestWatcher
-
getErrorScreenshotFile
Parameters:
description
- testDescription
Returns:
Failure screenshot file.
-