zoukankan      html  css  js  c++  java
  • Selenium webdriver实现截图功能

    可参考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 然后截图
  • 相关阅读:
    Runtime类
    递归(99乘法表)
    计算某天是在一年中的第几天
    数组逆序输出
    打印数组格式
    选择排序(直接把最小或最大的数选出来排列)
    冒泡排序
    比较两个字符数组是否相等
    汉字转阿斯克马值
    R语言调用C函数
  • 原文地址:https://www.cnblogs.com/yuanchunli/p/5164246.html
Copyright © 2011-2022 走看看