Created
July 25, 2019 06:06
-
-
Save safebear/814cd0955ed3a3aaf16032c7f477be92 to your computer and use it in GitHub Desktop.
Your ScreenShots Class
This file contains 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
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