【问题标题】:Cucumber extent report - how to add screenshot of failed case to the extent report黄瓜范围报告-如何将失败案例的屏幕截图添加到范围报告中
【发布时间】:2020-07-07 06:20:07
【问题描述】:

我在 Cucumber (Java) 中的范围报告中找不到失败案例的屏幕截图的解决方案。我在 Stack Overflow 的其他地方看过。任何人都可以帮我解决问题吗?文件 pom.xml 发布我对 Cucumber 报告的依赖项

<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());
           }  
              }

【问题讨论】:

  • youtube.com/watch?v=1kYn44-5Fy4此链接将帮助您创建失败的方法
  • 感谢您的评论!我假设这是带有 testNG 的代码,我在问我们如何将屏幕截图添加到范围报告中。

标签: java selenium cucumber extentreports


【解决方案1】:
  1. scenario.embed 将屏幕截图添加到黄瓜默认报告中。
  2. 此链接将解决您将屏幕截图附加到范围报告的问题。

https://www.toolsqa.com/selenium-cucumber-framework/cucumber-extent-report/

【讨论】:

  • 嗨,我已经通过添加 Files.copy(screenshot_with_scenario_name.toPath(), destinationPath.toPath()); 编辑了我上面的帖子。结果没有变化,仍然没有来自范围报告的屏幕截图。有什么建议吗?
  • 删除 FileUtils.Copyfile 看看是否有帮助。
猜你喜欢
  • 2018-11-28
  • 1970-01-01
  • 2021-08-22
  • 2020-04-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多