1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
public String TakeScreenShot(WebDriver driver) { try { //Get the random number for the file Random rand = new Random(); long random = (int )(Math.random() * 999999999 + 1000000); String result = Long.toString(random); String path = System.getProperty("user.dir") + "//" +"ScreenShots"; String nameFileName = result + ".png"; String filePathName = path + "//" + nameFileName; //to create new folder new File(path).mkdirs(); // TODO Auto-generated method stub TakesScreenshot scrShot = (TakesScreenshot)driver; File srcFile = scrShot.getScreenshotAs(OutputType.FILE); File destFile = new File(filePathName); Files.copy(srcFile.toPath(), destFile.toPath()); //WriteLogAndReport(logger, "info", "info", "Screen Shot taken at location: " + path); //Reporter.log("Screen shot taken and kept at path: " + filePathName ); Reporter.log("<a href = '" +filePathName + "'>My ScreenShot link</a>"); return filePathName; }catch (Exception e) { e.printStackTrace(); return null; } } |