Open Yoganand1995 opened 4 years ago
Hi ,
Below is the code I'm using to get the extent reports for my framework and the images are not loaded in the html reports and please guide me on the issue.
<dependency> <groupId>com.aventstack</groupId> <artifactId>extentreports</artifactId> <version>5.0.3</version> </dependency>
Base class method to get the screenshot
` public String getScreenshot(String MethodName, WebDriver FailedDriver) throws IOException { TakesScreenshot ScrShot = (TakesScreenshot) FailedDriver; File Source = ScrShot.getScreenshotAs(OutputType.FILE); String DesFile = System.getProperty("user.dir")+"\\reports\\Screenshots\\"+MethodName+".jpg"; FileUtils.copyFile(Source,new File(DesFile).getAbsoluteFile()); return DesFile; }`
Extent Report class
`public class ExtentReport { public static ExtentReports extent; public static ExtentReports getReport(){ String path = System.getProperty("user.dir") + "\\reports\\HtmlReports\\index.html"; ExtentSparkReporter reporter = new ExtentSparkReporter(path); reporter.config().setReportName("Web Automation Results"); reporter.config().setDocumentTitle("Test Results"); extent = new ExtentReports(); extent.attachReporter(reporter); extent.setSystemInfo("Tester","Yogananda"); return extent; } }`
TestNG Listener Method for the fail
`public void onTestFailure(ITestResult result) { Test.fail(result.getThrowable()); WebDriver FailedDriver = null; String MethodName = result.getMethod().getMethodName(); try { FailedDriver= (WebDriver)result.getTestClass().getRealClass() .getDeclaredField("Driver").get(result.getInstance()); } catch (Exception e) { e.printStackTrace(); } try { Test.addScreenCaptureFromPath(getScreenshot(MethodName,FailedDriver),MethodName); } catch (IOException e) { e.printStackTrace(); } }`
screenshot of the issue
I ran into this as well, there's no image attached at all
To fix this, kindly get
There You GO!!
Hi ,
Below is the code I'm using to get the extent reports for my framework and the images are not loaded in the html reports and please guide me on the issue.
Base class method to get the screenshot
Extent Report class
TestNG Listener Method for the fail
screenshot of the issue