Skip to content

Instantly share code, notes, and snippets.

@mitsuruog
Created September 3, 2012 09:40
Show Gist options
  • Save mitsuruog/3608144 to your computer and use it in GitHub Desktop.
Save mitsuruog/3608144 to your computer and use it in GitHub Desktop.
Selenium2 Capture Sample
private WebDriver driver;
protected void capture(String path) throws IOException {
WebDriver driver = this.driver;
if (driver instanceof HtmlUnitDriver) {
return;
} else if (driver instanceof RemoteWebDriver) {
driver = new Augmenter().augment(this.driver);
} else {
// 何もしない
}
File file = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(file, new File(path));
}
@Test
public void test() throws IOException {
driver.get("https://www.google.co.jp/");
capture("./img/google1.jpg");
driver.findElement(By.id("gbqfq")).clear();
driver.findElement(By.id("gbqfq")).sendKeys("selenium");
capture("./img/google2.jpg");
driver.findElement(By.linkText("Selenium - Web Browser Automation")).click();
capture("./img/google3.jpg");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment