zoukankan      html  css  js  c++  java
  • WebDriver与文件系统

    1.屏幕截屏操作:其接口函数是TakesScreenshot。该功能是在运行测试用例的过程中,需要验证某个元素的状态或者显示的数值时,可以将屏幕截取下来进行对比;或者在异常或者错误发生的时候将屏幕截取并保存起来,供后续分析和调式所用。

    package test;
    
    import java.io.File;
    import java.io.IOException;
    
    import org.apache.commons.io.FileUtils;
    import org.openqa.selenium.By;
    import org.openqa.selenium.OutputType;
    import org.openqa.selenium.TakesScreenshot;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    
    import common.StartFireFox;
    
    public class TestFile {
        public static void main(String[] args) {
            WebDriver driver = StartFireFox.start();
            driver.get("http://www.baidu.com");
            //截取当前页面。截取的图片以文件形式返回
            File srcFile=  ((TakesScreenshot) driver) .getScreenshotAs(OutputType.FILE);
     
            try {   //保存截取的图片
                    FileUtils.copyFile(srcFile,new File("selenium2/screenshot.png") );     
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
         
            driver.quit();
            System.out.println("close firefox browser");
        }
    }

  • 相关阅读:
    类加载器ClassLoader
    JAVA分别获取日期中的年、月、日
    sql 安全问题
    马尔科夫链
    触发器、锁、事务和事务控制
    索引、视图、存储过程、函数、游标
    字符集
    数据类型选择
    存储引擎
    错误:too many indices for array
  • 原文地址:https://www.cnblogs.com/claudia/p/5315522.html
Copyright © 2011-2022 走看看