FileUtils not showing suggestion to import predefined class for Screenshot functionality in selenium WebDriver

前端 未结 3 1836
小鲜肉
小鲜肉 2021-01-15 15:46

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 solu

相关标签:
3条回答
  • 2021-01-15 16:35

    Yes with Selenium Latest version we should use FileHandler.copy() It works and doesn't throw any error.

    // Take Screenshots example
    File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
    FileHandler.copy(scrFile, new File("<your path>\\screenshot.png"));
    
    0 讨论(0)
  • 2021-01-15 16:37

    The line FileUtils.copyFile(); has been updated to FileHandler.copy()

    0 讨论(0)
  • 2021-01-15 16:46

    FileUtils Class

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

    • 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 is bundled along with selenium-server-standalone-x.y.z by default and available ready to use.

    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 :

    • 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.

    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.

    0 讨论(0)
提交回复
热议问题