|
13 | 13 | import env.BaseTest;
|
14 | 14 |
|
15 | 15 | public class ScreenShotMethods implements BaseTest {
|
16 |
| - /** Method to take screen shot and save in ./Screenshots folder */ |
| 16 | + |
| 17 | + public ScreenShotMethods() { |
| 18 | + } |
| 19 | + |
17 | 20 | public void takeScreenShot() throws IOException {
|
18 |
| - File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); |
| 21 | + File scrFile = (File) ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); |
| 22 | + |
| 23 | + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss"); |
19 | 24 |
|
20 |
| - DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); |
21 | 25 | Calendar cal = Calendar.getInstance();
|
22 | 26 | System.out.println(dateFormat.format(cal.getTime()));
|
23 | 27 |
|
24 | 28 | String scrFilepath = scrFile.getAbsolutePath();
|
25 |
| - System.out.println("scrFilepath: " + scrFilepath); |
26 | 29 |
|
27 |
| - File currentDirFile = new File("Screenshots"); |
28 |
| - String path = currentDirFile.getAbsolutePath(); |
29 |
| - System.out.println("path: " + path + "+++"); |
| 30 | + System.out.println((new StringBuilder("scrFilepath: ")).append(scrFilepath).toString()); |
30 | 31 |
|
31 |
| - System.out.println("****\n" + path + "\\screenshot" + dateFormat.format(cal.getTime()) + ".png"); |
| 32 | + File currentDirFile = new File("Screenshots"); |
32 | 33 |
|
33 |
| - FileUtils.copyFile(scrFile, new File(path + "\\screenshot" + dateFormat.format(cal.getTime()) + ".png")); |
| 34 | + String path = currentDirFile.getAbsolutePath(); |
34 | 35 |
|
35 |
| - /* |
36 |
| - * DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); |
37 |
| - * Calendar cal = Calendar.getInstance(); |
38 |
| - * System.out.println(dateFormat.format(cal.getTime())); |
39 |
| - */ |
| 36 | + FileUtils.copyFile(scrFile, |
| 37 | + new File((new StringBuilder(String.valueOf(path))).append(File.separator + "screenshot-") |
| 38 | + .append(dateFormat.format(cal.getTime())).append(".png").toString())); |
40 | 39 | }
|
41 |
| - /* |
42 |
| - * cur_time = Time.now.strftime('%Y%m%d%H%M%S%L') |
43 |
| - * $driver.save_screenshot('./features/screenshots/screenshot' + cur_time + |
44 |
| - * '.png') |
45 |
| - */ |
46 | 40 | }
|
0 commit comments