Skip to content

Commit 6f709af

Browse files
Make sure that it works with any OSs (Windows/Mac)
1 parent 9eeac3b commit 6f709af

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

src/main/java/methods/ScreenShotMethods.java

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,28 @@
1313
import env.BaseTest;
1414

1515
public class ScreenShotMethods implements BaseTest {
16-
/** Method to take screen shot and save in ./Screenshots folder */
16+
17+
public ScreenShotMethods() {
18+
}
19+
1720
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");
1924

20-
DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
2125
Calendar cal = Calendar.getInstance();
2226
System.out.println(dateFormat.format(cal.getTime()));
2327

2428
String scrFilepath = scrFile.getAbsolutePath();
25-
System.out.println("scrFilepath: " + scrFilepath);
2629

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());
3031

31-
System.out.println("****\n" + path + "\\screenshot" + dateFormat.format(cal.getTime()) + ".png");
32+
File currentDirFile = new File("Screenshots");
3233

33-
FileUtils.copyFile(scrFile, new File(path + "\\screenshot" + dateFormat.format(cal.getTime()) + ".png"));
34+
String path = currentDirFile.getAbsolutePath();
3435

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()));
4039
}
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-
*/
4640
}

0 commit comments

Comments
 (0)