`
xitong
  • 浏览: 6198189 次
文章分类
社区版块
存档分类
最新评论

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();
}
}


}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics