selenium测试(Java)--截图(十九)

 1 package com.test.screenshot;
 2 
 3 import java.io.File;
 4 import java.io.IOException;
 5 
 6 import org.apache.commons.io.FileUtils;
 7 import org.openqa.selenium.OutputType;
 8 import org.openqa.selenium.TakesScreenshot;
 9 import org.openqa.selenium.WebDriver;
10 import org.openqa.selenium.firefox.FirefoxDriver;
11 
12 public class ScreenShotTest {
13 
14     public static void main(String[] args) {
15         WebDriver driver = new FirefoxDriver();
16         driver.get("http://www.baidu.com");
17 
18         //截图到output
19         File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
20         try {
21             String savePath = "D:\10-selenium\workspace\SeleniumTest"
22                     + "\src\com\test\screenshot\screenshot.png";
23             //复制内容到指定文件中
24             FileUtils.copyFile(scrFile, new File(savePath));
25         } catch (IOException e) {
26             e.printStackTrace();
27         }
28 
29     }
30 
31 }
原文地址:https://www.cnblogs.com/moonpool/p/5677782.html