File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed
src/test/java/io/github/mfaisalkhatri/utils Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change 4
4
import java .io .IOException ;
5
5
import java .nio .file .Files ;
6
6
import java .nio .file .Paths ;
7
+ import java .text .SimpleDateFormat ;
8
+ import java .util .Date ;
7
9
8
10
import org .openqa .selenium .OutputType ;
9
11
import org .openqa .selenium .TakesScreenshot ;
@@ -16,14 +18,17 @@ public class ScreenshotListener implements ITestListener {
16
18
public void onTestFailure (final ITestResult result ) {
17
19
Object testClass = result .getInstance ();
18
20
WebDriver driver = ((WebDriverProvider ) testClass ).getDriver ();
21
+ String timestamp = new SimpleDateFormat ("yyyyMMdd_HHmmss_SSS" ).format (new Date ());
22
+
19
23
20
24
if (driver != null ) {
21
25
String testName = result .getMethod ()
22
26
.getMethodName ();
23
27
File screenshot = ((TakesScreenshot ) driver ).getScreenshotAs (OutputType .FILE );
28
+ String filename = timestamp + ".png" ;
24
29
try {
25
30
Files .createDirectories (Paths .get ("screenshots" ));
26
- Files .copy (screenshot .toPath (), Paths .get ("screenshots" , testName + ".png" ));
31
+ Files .copy (screenshot .toPath (), Paths .get (testName , filename ));
27
32
} catch (IOException e ) {
28
33
throw new RuntimeException (e );
29
34
}
You can’t perform that action at this time.
0 commit comments