|
21 | 21 |
|
22 | 22 | import constants.GlobalConstants; |
23 | 23 | import decorators.Driver; |
| 24 | +import drivermanager.DriverManager; |
24 | 25 | import logsetup.Log; |
25 | 26 | import reports.ExtentReport; |
26 | 27 | import utilities.ScreenshotUtility; |
@@ -68,22 +69,17 @@ public void onTestSuccess(ITestResult result) { |
68 | 69 | @Override |
69 | 70 | public void onTestFailure(ITestResult result) { |
70 | 71 | String testDesc=result.getMethod().getDescription(); |
71 | | - |
72 | | - //Getting the driver from result parameter for taking the screenshot on failure of test |
73 | | - try { |
74 | | - Driver driver = (Driver)result.getTestClass().getRealClass().getField("driver").get(result.getInstance()); |
75 | | - |
| 72 | + try { |
76 | 73 | //Take screenshot and copying to Screenshot folder in the project |
77 | 74 | String screenshotsFolderPath =GlobalConstants.SCREENSHOT_FOLDER + testDesc + ".png"; |
78 | 75 |
|
79 | | - //Call takescreenshot() method from DriverLogger class and copying the screenshot from source path to Screenshot folder |
80 | | - //FileHandler.copy(((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE), |
81 | | - // new File(screenshotsFolderPath)); |
82 | | - |
| 76 | + //Call takescreenshot() method from DriverLogger class and copying the screenshot from source path to Screenshot folder |
| 77 | + FileHandler.copy(ScreenshotUtility.getscreenshot(),new File(screenshotsFolderPath)); |
| 78 | + |
83 | 79 | //Add screenshot from Screenshot folder to extent report |
84 | | - //extentTest.addScreenCaptureFromPath(screenshotsFolderPath); |
| 80 | + extentTest.addScreenCaptureFromPath(screenshotsFolderPath); |
85 | 81 |
|
86 | | - } catch (IllegalArgumentException | SecurityException | NoSuchFieldException | IllegalAccessException | WebDriverException e) { |
| 82 | + } catch (IllegalArgumentException | SecurityException | WebDriverException | IOException e) { |
87 | 83 | e.printStackTrace(); |
88 | 84 | } |
89 | 85 |
|
|
0 commit comments