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 Class
FileUtils
Class is defined in org.apache.commons.io.FileUtils which provides the general file manipulation utilities in the following areas :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 :
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.