FileUtils没有显示建议为硒WebDriver中的屏幕快照功能导入预定义的类 [英] FileUtils not showing suggestion to import predefined class for Screenshot functionality in selenium WebDriver

查看:130
本文介绍了FileUtils没有显示建议为硒WebDriver中的屏幕快照功能导入预定义的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不允许在程序中使用FileUtils,这样做时会显示错误.甚至没有建议显示要导入此预定义的类.我尝试搜索解决方案,但发现是导入该类.但就我而言,甚至没有建议显示要导入任何类.悬停在"FileUtils"上显示了创建FileUtils类/接口的建议.下面是我的代码:

I am not allowed to use FileUtils in the program and error is shown when doing so. Even no suggestion is showing to import this pre-defined Class. I tried to search the solution but what I found was to import the class. But in my case even suggestion is not showing to import any class. Hovering on the "FileUtils" shows the suggestion to create FileUtils class/interface. Below is my code:

 package captureScreenshot;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils; //Getting Error at this line
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

import com.google.common.io.Files;

public class FacebookScreenshot {

@Test
    public void captureScreenshot() throws IOException
{
    WebDriver driver = new FirefoxDriver();
    driver.manage().window().maximize();
    driver.get("https://www.facebook.com");
    driver.findElement(By.xpath("//input[@name='firstname']")).sendKeys("Anil Kumar");

    TakesScreenshot ts = (TakesScreenshot) driver;
    File source = ts.getScreenshotAs(OutputType.FILE);
    FileUtils.copyfile(source,new File("./Screenshots/facebook.png")); //Getting error at this line

    driver.quit();

    }

}

推荐答案

FileUtils类

FileUtils 类在 org.apache.commons.io.FileUtils 中定义,该类在以下提供了通用文件操作实用程序区域:

FileUtils Class

FileUtils Class is defined in org.apache.commons.io.FileUtils which provides the general file manipulation utilities in the following areas :

  • 写入文件
  • 从文件读取
  • 创建一个包含父目录的目录
  • 复制文件和目录
  • 删除文件和目录
  • 与URL相互转换
  • 按过滤器和扩展名列出文件和目录
  • 比较文件内容
  • 文件上次更改日期
  • 计算校验和
  • writing to a file
  • reading from a file
  • make a directory including parent directories
  • copying files and directories
  • deleting files and directories
  • converting to and from a URL
  • listing files and directories by filter and extension
  • comparing file content
  • file last changed date
  • calculating a checksum

org.apache.commons.io selenium-server-standalone-x.y.z 捆绑在一起,并且可以立即使用.

org.apache.commons.io is bundled along with selenium-server-standalone-x.y.z by default and available ready to use.

但是,您观察到的行为与用例差不多,其中提到您不允许在程序中使用 FileUtils >.可以是以下提到的两种情况之一:

But the behavior you are observing is pretty much inline with your usecase where you mentioned that you are not allowed to use FileUtils in the program. It can be either of the scenarios as mentioned below :

  • 如果您从 selenium-java-3.9.1 客户端使用 JAR ,则 JAR 包含 org.apache.commons .io 未添加到您的项目中.
  • 如果您将 Maven selenium-java-3.9.1 客户端依赖项一起使用,则排除了包含 FileUtils Class 的模块.
  • li>
  • Incase you are using JARs from selenium-java-3.9.1 client, the JAR containing org.apache.commons.io is not being added to your project.
  • Incase you are using Maven with selenium-java-3.9.1 client dependency the modules containing FileUtils Class have been excluded.

由于以下上述原因,当您在程序中提到 FileUtils 时,它没有显示任何导入类的建议.此外,如果您强行提供导入,它将在该行显示错误.

For the following above mentioned reasons, when you mention FileUtils in your program it doesn't show any suggestion to import the class. Moreover if you forcefully provide the import, it will show error on that line.

这篇关于FileUtils没有显示建议为硒WebDriver中的屏幕快照功能导入预定义的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆