public class ScreenshotTestWatcher extends BrowserTestWatcher
BrowserConfig.getSaveFolder()
/screenshots. Screenshot will also
be logged to the current tests report if there is an active test.
Note that when using this watcher, do not quit the browser. If the browser has been quit during the test or in an @After, this watcher will do nothing!
Example usage of this watcher:
import org.junit.*;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.ExpectedConditions;
import edu.uci.qa.browserdriver.BrowserDriver;
import edu.uci.qa.browserdriver.testing.BrowserProvider;
import edu.uci.qa.browserdriver.testing.ScreenshotTestWatcher;
public class ScreenshotTest implements BrowserProvider {
BrowserDriver driver = null;
@Rule
public ScreenshotTestWatcher watcher = new ScreenshotTestWatcher(this);
@Before
public void createBrowser() {
driver = BrowserDriver.createBrowser();
}
@Test
public void basicTest() throws Throwable {
driver.get("http://www.google.com");
driver.sendKeys(By.xpath("//*[ @name='q']"), "webdriver").submit();
driver.waitUntil(
ExpectedConditions.presenceOfElementLocated(
By.xpath("//*[ @id='rso' or @id='resultStats']")));
Assert.assertEquals("WRONG", driver.getTitle()); // This assert will always fail!
}
@Override
public BrowserDriver getBrowser() {
return driver;
}
}
Modifier and Type | Field and Description |
---|---|
protected Screenshot |
failShot |
provider, verboseMode
Constructor and Description |
---|
ScreenshotTestWatcher(BrowserProvider provider) |
ScreenshotTestWatcher(BrowserProvider provider,
boolean verboseMode) |
Modifier and Type | Method and Description |
---|---|
protected void |
failed(Throwable e,
org.junit.runner.Description description) |
protected void |
skipped(org.junit.AssumptionViolatedException e,
org.junit.runner.Description description) |
protected void |
succeeded(org.junit.runner.Description description) |
protected Screenshot failShot
public ScreenshotTestWatcher(BrowserProvider provider)
public ScreenshotTestWatcher(BrowserProvider provider, boolean verboseMode)
protected void succeeded(org.junit.runner.Description description)
succeeded
in class org.junit.rules.TestWatcher
protected void skipped(org.junit.AssumptionViolatedException e, org.junit.runner.Description description)
skipped
in class org.junit.rules.TestWatcher
protected void failed(Throwable e, org.junit.runner.Description description)
failed
in class org.junit.rules.TestWatcher
Copyright © 2019. All rights reserved.