Created
September 3, 2012 09:40
-
-
Save mitsuruog/3608144 to your computer and use it in GitHub Desktop.
Selenium2 Capture Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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