我已为范围报告添加了maven依赖项:
<dependency>
<groupId>com.vimalselvam</groupId>
<artifactId>cucumber-extentsreport</artifactId>
<version>2.0.4</version>
</dependency>
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>3.0.5</version>
<scope>provided</scope>
</dependency>.
在跑步者类中,我已经在Cucumber选项中指定了插件:
@CucumberOptions(
features={"src/test/java/features/Exception.feature"},strict = true
,glue={"com.selenium.wrapper","stepDefinitaion"},
format = { "pretty","html:target/site/cucumber-pretty","html:target/cucumber-report","json:target/cucumber.json" },
plugin = {"com.cucumber.listener.ExtentCucumberFormatter:output/report.html"}
在@After钩子我添加了代码来添加截图:
// *添加代码以截取屏幕并保存
Reporter.addScreenCaptureFromPath("path of the screenshot");
执行后,添加一个空白图像:image 2 shows the blank screenshot
您是否尝试将屏幕截图保存为.png文件。我在嵌入保存为.jpg文件的屏幕截图时遇到了同样的问题。
对于Cucumber扩展报告嵌入由于这个不起作用,我们必须保存图像然后
File sourcePath = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
File destinationPath = new File(System.getProperty("user.dir") + "/target/test-report/extent-report/screenshots/" + screenshotName + ".png");
copyFile(sourcePath, destinationPath); Reporter.addScreenCaptureFromPath("./screenshots/"+screenshotName+".png");
使用“.png”扩展名保存屏幕截图。使用.jpg文件嵌入图像时出现问题。我遇到了同样的问题,我将.jpg修改为.png,屏幕截图嵌入到范围报告中。