While implementing takeScreenshot function in BaseTest in Module-23[TestNG Core DDF], getting following exception-
Cannot make a static reference to the non-static method copyFile(File, File) from the type FileUtils
The code for this takeScreenshot fuction is just copied from your code and hencenot able to understand the exception.
Also added screenshot for reference.
CODE:
public void takeScreenShot(){
// fileName of the screenshot
Date d=new Date();
String screenshotFile=d.toString().replace(":", "_").replace(" ", "_")+".png";
// store screenshot in that file
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
try {
FileUtils.copyFile(scrFile, new File(System.getProperty("user.dir")+"//screenshots//"+screenshotFile));
} catch (IOException e) {
.printStackTrace();
}
//put screenshot file in reports
test.log(LogStatus.INFO,"Screenshot-> "+ test.addScreenCapture(System.getProperty("user.dir")+"//screenshots//"+screenshotFile));
}
Instructor
Ashish Thakur Replied on 01/07/2019
You need to import FileUtils from commons-io.
Use the below dependency for that
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>