webdriver 截图公用方法

import java.io.File;
import java.io.IOException;
import java.util.Calendar;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import com.google.common.io.Files;


public class ScreenShot {
static Calendar ca = Calendar.getInstance();
static int day=ca.get(Calendar.DATE);//获取日
static int minute=ca.get(Calendar.MINUTE);//分
static int hour=ca.get(Calendar.HOUR);//小时

public static void takeScreenShot(String name,WebDriver driver) {
String data=day+"_"+hour+"_"+minute;
File scrFile = ((TakesScreenshot) driver)
.getScreenshotAs(OutputType.FILE);


try {
Files.copy(scrFile, new File("d:\\webdriver\\" +data+name+".jpeg"));
System.out.println("截图成功!");
} catch (IOException e) {
e.printStackTrace();
}
}


}

你可能感兴趣的:(webdriver)