码迷,mamicode.com
首页 > Web开发 > 详细

Selenium webdriver截图

时间:2017-02-15 18:36:31      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:test   log   form   drive   utils   ota   otf   cep   sel   

java语言,进行截图的代码如下:

public void screenshot(WebDriver driver){
File screenShotFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);//截图代码
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd_HHmmss");//设置日期格式
//将截图剪切到指定路径
try{
FileUtils.moveFile(screenShotFile, new File("test-output/snapshot/" + df.format(new Date())+ ".jpg"));
}catch(IOException e){
System.out.println("can‘t save screenshot");
}
}

 

其中关键的代码是

File screenShotFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE)

  

Selenium webdriver截图

标签:test   log   form   drive   utils   ota   otf   cep   sel   

原文地址:http://www.cnblogs.com/qianjin100/p/6402432.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!