File tree 1 file changed +22
-0
lines changed
webdriver_java/src/test/java/base
1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 1
1
package base ;
2
2
3
+ import com .google .common .io .Files ;
4
+ import org .openqa .selenium .OutputType ;
5
+ import org .openqa .selenium .TakesScreenshot ;
3
6
import org .openqa .selenium .WebDriver ;
4
7
import org .openqa .selenium .chrome .ChromeDriver ;
8
+ import org .testng .ITestResult ;
5
9
import org .testng .annotations .AfterClass ;
10
+ import org .testng .annotations .AfterMethod ;
6
11
import org .testng .annotations .BeforeClass ;
7
12
import org .testng .annotations .BeforeMethod ;
8
13
import pages .HomePage ;
9
14
import utils .WindowManager ;
10
15
16
+ import java .io .File ;
17
+ import java .io .IOException ;
18
+
11
19
public class BaseTests {
12
20
13
21
private WebDriver driver ;
@@ -31,6 +39,20 @@ public void tearDown(){
31
39
driver .quit ();
32
40
}
33
41
42
+ @ AfterMethod
43
+ public void recordFailure (ITestResult result ){
44
+ if (ITestResult .FAILURE == result .getStatus ())
45
+ {
46
+ var camera = (TakesScreenshot )driver ;
47
+ File screenshot = camera .getScreenshotAs (OutputType .FILE );
48
+ try {
49
+ Files .move (screenshot , new File ("resources/screenshots/" + result .getName () + ".png" ));
50
+ }catch (IOException e ){
51
+ e .printStackTrace ();
52
+ }
53
+ }
54
+ }
55
+
34
56
public WindowManager getWindowManager (){
35
57
return new WindowManager (driver );
36
58
}
You can’t perform that action at this time.
0 commit comments