Please find the code below i am using ExtentReport 3.0.6 and selenium 3.4.0. Screenshots are not saving but i am not getting any exceptions. It's not saving any screenshots. I am not sure why it's happening it was working for me couple of days back.
ExtentHtmlReporter htmlReporter;
ExtentReports extent;
ExtentTest test;
WebDriver driver;
@BeforeTest
public void setUp()
{
//where we need to generate the report
htmlReporter = new ExtentHtmlReporter(System.getProperty("user.dir")+"/test-output/MyReport.html");
extent = new ExtentReports();
extent.attachReporter(htmlReporter);
// Set our document title, theme etc..
htmlReporter.config().setDocumentTitle("My Test Report");
htmlReporter.config().setReportName("Test Report");
htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
htmlReporter.config().setTheme(Theme.DARK);
}
@Test
public void demoReportPass()
{
test = extent.createTest("demoScreenshotTest");
System.setProperty("webdriver.chrome.driver","C:\\SeleniumServer\\chromedriver.exe");
driver=new ChromeDriver();
driver.get("https://www.google.com/");
String title = driver.getTitle();
Assert.assertEquals(title, "Goo");
}
@AfterMethod
public void getResult(ITestResult result) throws IOException
{
if(result.getStatus()==ITestResult.FAILURE)
{
String screenshotPath = capture(driver, "screenshotname");
//String screenshotPath = GetScreenshot.captureFullPage(driver, "screenshotname");
test.log(Status.FAIL, MarkupHelper.createLabel(result.getName() + "Test Case failed due to below issues", ExtentColor.RED));
test.fail(result.getThrowable());
test.fail("Snapshot below: " + test.addScreenCaptureFromPath(screenshotPath));
}
}
@AfterSuite
public void tearDown()
{
extent.flush();
driver.quit();
}
public String capture(WebDriver driver, String screenShotName) throws IOException
{
TakesScreenshot ts = (TakesScreenshot)driver;
File source = ts.getScreenshotAs(OutputType.FILE);
String dest = "../test-output/"+screenShotName+".png";
File destination = new File(dest);
FileUtils.copyFile(source, destination);
return dest;
}