Selenium-Webdriver 自动截图的方法
上一篇 /
下一篇 2013-12-16 15:51:11
/ 个人分类:Selenium
如下是Webdriver自动截图的方法,然后再主程序中或者需要用到截屏的地方调用如下方法(takeScreenShot)即可。
importjava.io.File;
importjava.io.IOException;
importjava.util.Calendar;
importorg.openqa.selenium.OutputType;
importorg.openqa.selenium.TakesScreenshot;
importorg.openqa.selenium.WebDriver;
importcom.google.common.io.Files;
publicclassScreenShot {
staticCalendarca= Calendar.getInstance();
staticintday=ca.get(Calendar.DATE);//获取日
staticintminute=ca.get(Calendar.MINUTE);//分
staticinthour=ca.get(Calendar.HOUR);//小时
publicstaticvoidtakeScreenShot(String name,WebDriver driver) {
String data=day+"_"+hour+"_"+minute;
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
try{
Files.copy(scrFile,newFile("d:\\webdriver\\"+data+name+".jpeg"));
System.out.println("截图成功!");
}
catch(IOException e) {
e.printStackTrace();
}
}
}
收藏
举报
TAG: