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);
        }
    }
  • 相关阅读:
    ntpdate
    动态查看日志
    eclipse proxy
    远程调试
    pe and elf
    03scikit-learn非监督学习
    15管家婆小项目
    02scikit-learn模型训练
    01scikit-learn数据集下载
    scikit-learn中文api
  • 原文地址:https://www.cnblogs.com/yanzhe/p/7516232.html
Copyright © 2011-2022 走看看