I found no solutions for the screenshot of failed case to the extent report in Cucumber (Java). I have look elsewhere in Stack Overflow. Can anyone kindly help me troubleshoot? File pom.xml
posting my dependencies for Cucumber reports
<dependency>
<groupId>com.relevantcodes</groupId>
<artifactId>extentreports</artifactId>
<version>2.41.2</version>
</dependency>
<dependency>
<groupId>com.vimalselvam</groupId>
<artifactId>cucumber-extentsreport</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>3.1.2</version>
</dependency>
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports-cucumber4-adapter</artifactId>
<version>1.0.6</version>
</dependency>
/*runner class */ plugin and run method
plugin = {"com.cucumber.listener.ExtentCucumberFormatter:target/cucumber-reports/report.html"}
public class testRunner{
@AfterClass
public static void writeExtentReport() {
Reporter.loadXMLConfig(new File("C:\\Users\\User\\eclipseworkspace\\test\\extent-config.xml"));
}
/* step class */
@After
public void execute_after_every_scenario(Scenario scenario) throws InterruptedException, IOException
{
testbase.teardown(scenario);
}
/* test base class */ what is working are the screenshots saved in output folder what is missing are the screenshots in extent report
public static void teardown(Scenario scenario) throws InterruptedException, IOException
{
Thread.sleep(2000);
if (scenario.isFailed()) {
try {
String screenshotName = scenario.getName().replaceAll(" ", "_");
byte[] screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES);
File screenshot_with_scenario_name = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
// FileUtils.copyFile(screenshot_with_scenario_name, new File("C:\\Users\\User\\eclipse-workspace\\test\\testscreenshots\\" + screenshotName + ".png"));
System.out.println("testing pring the screenshot" + screenshotName);
File destinationPath = new File("C:\\Users\\User\\eclipse-workspace\\test\\testscreenshots\\" + screenshotName + ".png");
//Copy taken screenshot from source location to destination location
Files.copy(screenshot_with_scenario_name.toPath(), destinationPath.toPath());
Reporter.addScreenCaptureFromPath(destinationPath.toString());
Reporter.addScenarioLog(screenshotName);
scenario.embed(screenshot, "image/png");
} catch (IOException somePlatformsDontSupportScreenshots) {
System.err.println(somePlatformsDontSupportScreenshots.getMessage());
}
}
https://www.toolsqa.com/selenium-cucumber-framework/cucumber-extent-report/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.