There are many times when we run our testcases there might be the possibility that testcases may fail and when the testcase may fail then the screenshot of the screen should be captured. We should use the following code to capture the screenshot:
System.out.println("Capturing snapshot of the screen");
File srcFile=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(srcFile, new File("Location of output file"));
NOTE: Do not give the location of output file as C drive. Due to security reasons windows many times does not allow to write anything in C drive. So, you would not be able to see the file in C drive. If we give only the file name without directory then the file is saved in the root directory of the project.
1 Comment(s)