-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.java
More file actions
31 lines (26 loc) · 1017 Bytes
/
Utils.java
File metadata and controls
31 lines (26 loc) · 1017 Bytes
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
package utils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.io.FileHandler;
import java.io.File;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class Utils {
public static String takeScreenshot(String name, WebDriver driver) {
File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH.mm.ss");
File screenshotsDirectory = new File("screenshots/");
if (!screenshotsDirectory.exists()){
screenshotsDirectory.mkdirs();
}
String path = "screenshots/" + name + "_" + formatter.format(LocalDateTime.now()) + ".png";
try {
FileHandler.copy(screenshot, new File(path));
} catch (IOException e) {
e.printStackTrace();
}
return path;
}
}