Skip to content

Instantly share code, notes, and snippets.

@safebear
Created July 25, 2019 06:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save safebear/814cd0955ed3a3aaf16032c7f477be92 to your computer and use it in GitHub Desktop.
Save safebear/814cd0955ed3a3aaf16032c7f477be92 to your computer and use it in GitHub Desktop.
Your ScreenShots Class
public class Screenshots {
public static String generateScreenShotFileName(){
// create filename
return new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date()) + ".png";
}
public static void capturescreenshot(WebDriver driver, String fileName) {
// Take screenshot
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
// Make sure that the 'screenshots' directory exists
File file = new File("target/screenshots");
if (!file.exists()) {
if (file.mkdir()) {
System.out.println("Directory is created!");
} else {
System.out.println("Failed to create directory!");
}
}
// Copy file to filename and location we set before
try {
copy(scrFile, new File("target/screenshots/" + fileName));
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment