Reputation: 29
I am unable to add the screenshot of failed case to the extent report in Cucumber (java).
//Runner class to generate extent report
@AfterClass
public static void Report() {
Reporter.loadXMLConfig(new File("/Users/chetan/Documents/workspace/Packages/extent-config.xml"));
Properties p = new Properties();
p.list(System.out);
}
//Main class contains step definitions
@After("@browser")
public void teardown(WebDriver driver, Scenario scenario, String screenshotName) throws IOException {
if (scenario.isFailed()) {
final byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");
driver.quit();
}
}
Upvotes: 1
Views: 6530
Reputation: 45
This is question for extent reports cucumber adapter but answers are for extent reports. Please open report and see in console the link to the screenshot path and check if images are there.
It is known issue that extent adapters save screenshots in test-output folder for some reason, you may need to do put screenshot folder in extent.properties or use SystemSet
The problem was apparently solved in new snapshot but I have to check that
Upvotes: 0
Reputation: 4035
You need to define Extent Report Object at class Level or wherever you like. And then you can use it on Failure.
Code:
//Report Initialization
ExtentHtmlReporter htmlreport = new ExtentHtmlReporter(".\\Report\\Extent Report with Screenshot.html");
ExtentReports reports = new ExtentReports();
reports.attachReporter(htmlreport);
ExtentTest testlog;
//Capture and save screenshot
File screen = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
BufferedImage img = ImageIO.read(screen);
File filetest = Paths.get(".").toAbsolutePath().normalize().toFile();
ImageIO.write(img, "png", new File(filetest + "\\Screenshots\\" + "Test.png"));
//Log Screenshot in Report
testlog.info("Details of " + "Test screenshot", MediaEntityBuilder
.createScreenCaptureFromPath(System.getProperty("user.dir") + "\\Screenshots\\" + "Test.png").build());
//Flush Report-Mandatory, Else report will not generate.
reports.flush();
You can refer my example from Github (Click here), for ease of Use.
Upvotes: 1
Reputation: 50819
You didn't add the screenshot to the report
ExtentTest test = extent.createTest("TestName");
test.fail("details").addScreenCaptureFromPath("pathToScreenshot");
// or
test.fail("details", MediaEntityBuilder.createScreenCaptureFromPath("pathToScreenshot").build());
Upvotes: 0