|
1 | 1 | package listeners; |
2 | 2 |
|
3 | | -import java.awt.Desktop; |
4 | 3 | import java.io.File; |
5 | 4 | import java.io.IOException; |
6 | 5 | import java.util.Arrays; |
7 | 6 |
|
| 7 | +import org.openqa.selenium.WebDriver; |
8 | 8 | import org.openqa.selenium.io.FileHandler; |
9 | 9 | import org.testng.ISuite; |
10 | 10 | import org.testng.ISuiteListener; |
|
19 | 19 | import decorators.Driver; |
20 | 20 | import logsetup.Log; |
21 | 21 | import reports.ExtentReport; |
| 22 | +import utilities.ScreenshotUtility; |
22 | 23 |
|
23 | 24 | public class TestListener implements ITestListener, ISuiteListener{ |
24 | 25 | ExtentReports extentReport; |
@@ -66,19 +67,18 @@ public void onTestFailure(ITestResult result) { |
66 | 67 |
|
67 | 68 | //Getting the driver from result parameter for taking the screenshot on failure of test |
68 | 69 | try { |
69 | | - result.getTestClass().getRealClass().getFields(); |
70 | 70 | Driver driver = (Driver)result.getTestClass().getRealClass().getField("driver").get(result.getInstance()); |
71 | 71 |
|
72 | 72 | //Take screenshot and copying to Screenshot folder in the project |
73 | | - //String screenshotsFolderPath =System.getProperty("user.dir")+"/Screenshots/"+testDesc+".png"; |
| 73 | + String screenshotsFolderPath =System.getProperty("user.dir")+"/Screenshots/"+testDesc+".png"; |
74 | 74 |
|
75 | 75 | //Call takescreenshot() method from DriverLogger class and copying the screenshot from source path to Screenshot folder |
76 | | - //FileHandler.copy(driver.takescreenshot(), new File(screenshotsFolderPath)); |
| 76 | + //FileHandler.copy(ScreenshotUtility.takescreenshot(driver), new File(screenshotsFolderPath)); |
77 | 77 |
|
78 | 78 | //Add screenshot from Screenshot folder to extent report |
79 | 79 | //extentTest.addScreenCaptureFromPath(screenshotsFolderPath); |
80 | 80 |
|
81 | | - } catch (IllegalArgumentException | SecurityException | NoSuchFieldException | IllegalAccessException e) { |
| 81 | + } catch (IllegalArgumentException | SecurityException | NoSuchFieldException | IllegalAccessException e) { |
82 | 82 | e.printStackTrace(); |
83 | 83 | } |
84 | 84 |
|
|
0 commit comments