Last active
January 12, 2024 13:28
-
-
Save timothyshort/49228727983e6ed5c7c92e8f5fb04602 to your computer and use it in GitHub Desktop.
Take a screenshot of Selenium WebDriver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This method takes a screenshot of the browser and saves as a file | |
| public static void snap(WebDriver driver, String filename) { | |
| String rootFolder = "C:/Users/SeleniumProjects/TestOutput/"; | |
| File ScreenshotFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); // Create file from the screenshot of driver | |
| try { | |
| FileUtils.copyFile(ScreenshotFile, new File (rootFolder + filename + ".jpg")); | |
| } catch (IOException e) { | |
| System.out.println("Could not save the file"); | |
| e.printStackTrace(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
getting error msg
The method copyFile(File, File) is undefined for the type FileUtils