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 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 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.
-
Method Summary
All Methods 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.
-
-
-
Constructor Detail
-
ScreenshotOnFailureRule
public ScreenshotOnFailureRule(HasDriver driverHolder)
Creates a new ScreenshotOnFailureRule in the provided test case.
Parameters:
driverHolder
- TheHasDriver
instance 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
- 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 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:
failed
in classorg.junit.rules.TestWatcher
-
finished
protected void finished(org.junit.runner.Description description)
Overrides:
finished
in classorg.junit.rules.TestWatcher
-
getErrorScreenshotFile
protected File getErrorScreenshotFile(org.junit.runner.Description description)
Parameters:
description
- testDescription
Returns:
Failure screenshot file.
-
-