???????? ???????? ?????н??
package com.example.tests;
import java.io.File;
import org.apache.commons.io.FileUtils;
import org.junit.*;
import org.openqa.selenium.*;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class Selenium2 {
@Test
public void testTakesScreenshot() {
WebDriver driver = new InternetExplorerDriver();
driver.get("http://www.baidu.com");
try {
File srcFile = ((TakesScreenshot)driver).
getScreenshotAs(OutputType.FILE);
FileUtils.copyFile
(srcFile??new File("d:\screenshot.png"));
} catch (Exception e) {
e.printStackTrace();
}
driver.close();
}
}
????TakesScreenshot???????getScreenshotAs()????????????????????????У??????????OutputType.FILE????????????getScreenshoAs()???????????????????????????????????
?????????????RemoteWebDriver() ?????????????
???????????selenium java -jar selenium-server-standalone-2.25.0.jar
package com.example.tests;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import org.apache.commons.io.FileUtils;
import org.junit.*;
import org.openqa.selenium.*;
import org.openqa.selenium.remote.*;
public class Selenium2 {
@Test
public void testRemoteWebDriverScreenShot() {
//????????????
DesiredCapabilities capability = DesiredCapabilities.internetExplorer();
WebDriver driver = null;
try {
driver = new RemoteWebDriver( //?????localhost??????
new URL("http://localhost:4444/wd/hub")?? capability);
} catch (MalformedURLException e) {
e.printStackTrace();
}
driver.get("http://www.sina.com.cn");
//??????????н??
driver = new Augmenter().augment(driver);
File scrFile =
((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
try {
FileUtils.copyFile(scrFile?? new File("D:\screenshot.png"));
} catch (IOException e) {
e.printStackTrace();
}
}
}