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.TestWatcherThis JUnitRulegrabs 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 yourtearDown()method (annotated withAfter). 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
Constructors Constructor 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidfailed(Throwable throwable, org.junit.runner.Description description)protected 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.
-
-
-
Constructor Detail
-
ScreenshotOnFailureRule
public ScreenshotOnFailureRule(HasDriver driverHolder)
Creates a new ScreenshotOnFailureRule in the provided test case.- Parameters:
driverHolder- TheHasDriverinstance that holds the active WebDriver instance. Commonly this is theTestBenchTestCase.
-
ScreenshotOnFailureRule
public ScreenshotOnFailureRule(HasDriver driverHolder, boolean quitDriverOnFinish)
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 Detail
-
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
protected void failed(Throwable throwable, org.junit.runner.Description description)
- Overrides:
failedin classorg.junit.rules.TestWatcher
-
finished
protected void finished(org.junit.runner.Description description)
- Overrides:
finishedin classorg.junit.rules.TestWatcher
-
getErrorScreenshotFile
protected File getErrorScreenshotFile(org.junit.runner.Description description)
- Parameters:
description- testDescription- Returns:
- Failure screenshot file.
-
-