zoukankan      html  css  js  c++  java
  • selenium-java,UI自动化截图方法

    截图方法:

    import java.io.File;
    import java.io.IOException;
    import org.apache.commons.io.FileUtils;
    import org.openqa.selenium.OutputType;
    import org.openqa.selenium.TakesScreenshot;
    import org.openqa.selenium.WebDriver;
    
    public class Aiding_Method {
        
        /*
         * 参数
         * String screenPath:文件路径
         * 例:D:\图片\新增-上传-返回.jpg
         * WebDriver driver:测试类定义的driver对象
         */
        public void takeScreenshot(String screenPath, WebDriver driver) {
            try {
                File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);//OutputType.FILE--截幕保存为图片
                FileUtils.copyFile(scrFile, new File(screenPath));//把图片保存到指定路径 
            } catch (IOException e) {
                System.out.println("截图出现错误");
            }
        }
        
    }

    使用示例:

    public class Test {
        
        private WebDriver driver;
        
        @Before
        public void setUp() throws Exception {
            element_operation = new Element_operation();
            System.setProperty("webdriver.chrome.driver","D:\Configuration\chromedriver.exe");//谷歌浏览器路径
            driver = new ChromeDriver();
            driver.manage().window().maximize();//最大化浏览器
            driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
            driver.get("http://www.baidu.com");
        }
    
        @After
        public void tearDown() throws Exception {
            try {
                Thread.sleep(1000);
            } catch (Exception e) {
                // TODO: handle exception
            }
            driver.quit();
        }
    
        @Test
        public void test1() throws ParseException{
            Aiding_Method aiding_Method = new Aiding_Method();
            aiding_Method.takeScreenshot("C:\Users\Administrator\Desktop\1.jpg", driver);
        }
    }
  • 相关阅读:
    win7系统激活最简单方法
    如何删除计算机多系统中不需要了的系统?
    SQL SERVER 中 GO 的用法2
    SQL SERVER 中 GO 的用法
    SQL SERVER中架构的理解
    linux诡异的半连接(SYN_RECV)队列长度
    skbtrace
    IO之流程与buffer 图
    MYSQL 缓存详解 [myownstars] 经典博客
    TCP 函数
  • 原文地址:https://www.cnblogs.com/yanzhe/p/7516232.html
Copyright © 2011-2022 走看看