在测试时一般会在发生错误时,将错误页面截屏,这样就不用一直盯着运行的页面了。
public class WindoScreen {
public static void main(String[] args) throws IOException {
System.setProperty("webdriver.gecko.driver", "D:\\Crosscheck Browser Testing Framework\\geckodriver.exe");
System.setProperty("webdriver.firefox.bin", "D:\\firefox\\firefox.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.csdn.net/");
// 创建截图文件对象
File file = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
// 以日期给图片设置名称
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HHmmss");
String now = sdf.format(new Date());
Files.copy(file, new File("E:\\" + now + ".jpg"));
driver.quit();
}