Package com.vaadin.testbench
Class ScreenshotOnFailureRule
java.lang.Object
org.junit.rules.TestWatcher
com.vaadin.testbench.ScreenshotOnFailureRule
- All Implemented Interfaces:
org.junit.rules.TestRule
public class ScreenshotOnFailureRule
extends org.junit.rules.TestWatcher
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 voidprotected voidfinished(org.junit.runner.Description description) protected FilegetErrorScreenshotFile(org.junit.runner.Description description) voidsetQuitDriverOnFinish(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- TheHasDriverinstance that holds the active WebDriver instance. Commonly this is theTestBenchTestCase.
-
ScreenshotOnFailureRule
Creates a new ScreenshotOnFailureRule in the provided test case.- Parameters:
driverHolder- TheHasDriverinstance 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:
failedin classorg.junit.rules.TestWatcher
-
finished
protected void finished(org.junit.runner.Description description) - Overrides:
finishedin classorg.junit.rules.TestWatcher
-
getErrorScreenshotFile
- Parameters:
description- testDescription- Returns:
- Failure screenshot file.
-