我没有找到针对Cucumber(Java)中范围报告失败案例的屏幕截图的解决方案。我在堆栈溢出的其他地方看过。谁能帮我解决问题?文件pom.xml
发布了我对黄瓜报告的依赖性
<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类* /插件和运行方法
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"));
}
/ *步骤类* /
@After
public void execute_after_every_scenario(Scenario scenario) throws InterruptedException, IOException
{
testbase.teardown(scenario);
}
/ *测试基础类* / 起作用的是屏幕快照保存在输出文件夹中 缺少范围报告中的屏幕截图
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());
}
}
答案 0 :(得分:0)
https://www.toolsqa.com/selenium-cucumber-framework/cucumber-extent-report/