首页 > Web开发 > 详细

Selenium webdriver实现截图功能

时间:2016-01-27 19:37:12      阅读:344      评论:0      收藏:0      [点我收藏+]

可参考http://www.cnblogs.com/tobecrazy/p/3599568.html

Webdriver截图时,需要引入:

import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;

截图方法
public static void snapshot(TakesScreenshot drivername, String filename)
  {
      // this method will take screen shot ,require two parameters ,one is driver name, another is file name
      
    String currentPath = System.getProperty("user.dir"); //get current work folder
    System.out.println(currentPath);
    File scrFile = drivername.getScreenshotAs(OutputType.FILE);
        // Now you can do whatever you need to do with it, for example copy somewhere
        try {
            System.out.println("save snapshot path is:"+currentPath+"/"+filename);
            FileUtils.copyFile(scrFile, new File(currentPath+"\\"+filename));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            System.out.println("Can‘t save screenshot");
            e.printStackTrace();
        }
        finally
        {
           
            System.out.println("screen shot finished");
        }
  }


在百度上搜索 selenium 然后截图

 

Selenium webdriver实现截图功能

原文:http://www.cnblogs.com/yuanchunli/p/5164246.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!