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");
        }
    }

  • 相关阅读:
    关于application/x-www-form-urlencoded编码
    socket 状态
    TCP/IP三次握手详解
    一步步优化JVM四:决定Java堆的大小以及内存占用
    编码问题
    git 应用
    父与子继承
    python try except
    python 编码问题
    requests 库使用方法
  • 原文地址:https://www.cnblogs.com/claudia/p/5315522.html
Copyright © 2011-2022 走看看