【问题标题】:how can i send failed tests screenshots to reportportal. I am using Java + TestNG framework如何将失败的测试屏幕截图发送到报告门户。我正在使用 Java + TestNG 框架
【发布时间】:2021-03-13 17:12:54
【问题描述】:

我尝试使用以下代码将失败测试的屏幕截图发送到 reportPortal,但它对我不起作用。有人可以在这里提供帮助

public ReportPortalMessage failedScrenshot(String methodName) 
    {
        ReportPortalMessage message = null;
        String time = pg.subGrpUnique_monthdate();
        File srcfile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
        java.util.Date d= new java.util.Date();
        try
        {
                org.apache.commons.io.FileUtils.copyFile(srcfile, new File("./ScreenShots/"+d.toString().replace(":", "_")+".png"));                               message = new ReportPortalMessage(srcfile, rp_message);
            LOGGER.info("Screenshot taken.");
        }
        catch (IOException e)
        {
            e.printStackTrace();
            LOGGER.info("Unable to take screenshot.");
        }
         LOGGER.info(message);
         return message;   
    }

【问题讨论】:

  • 您需要分享什么是 ReportPortalMessage 类,因为目前看来您刚刚将其设置为 null。

标签: java reporting reportportal


【解决方案1】:

有些例子完全符合你的要求:

对于第一个示例屏幕截图将出现在@AfterMethod

对于后面的例子截图会出现在同一个测试方法中:

【讨论】:

    猜你喜欢
    • 2019-12-07
    • 2012-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多