File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
webdriver_java/src/test/java/base Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 11package base ;
22
3+ import com .google .common .io .Files ;
4+ import org .openqa .selenium .OutputType ;
5+ import org .openqa .selenium .TakesScreenshot ;
36import org .openqa .selenium .WebDriver ;
47import org .openqa .selenium .chrome .ChromeDriver ;
8+ import org .testng .ITestResult ;
59import org .testng .annotations .AfterClass ;
10+ import org .testng .annotations .AfterMethod ;
611import org .testng .annotations .BeforeClass ;
712import org .testng .annotations .BeforeMethod ;
813import pages .HomePage ;
914import utils .WindowManager ;
1015
16+ import java .io .File ;
17+ import java .io .IOException ;
18+
1119public class BaseTests {
1220
1321 private WebDriver driver ;
@@ -31,6 +39,20 @@ public void tearDown(){
3139 driver .quit ();
3240 }
3341
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+
3456 public WindowManager getWindowManager (){
3557 return new WindowManager (driver );
3658 }
You can’t perform that action at this time.
0 commit comments