【问题标题】:How to attach a Screenshot in ReportNG Test如何在 ReportNG 测试中附加屏幕截图
【发布时间】:2013-12-05 17:55:04
【问题描述】:

我需要一些帮助,附上 ReportNG 中失败测试用例的屏幕截图。 有人可以解释一下这是如何完成的。我是 Selenium 和 Java 的新手。 我使用 Maven 作为构建工具。

【问题讨论】:

    标签: java selenium testng reportng


    【解决方案1】:

    @Cagy79 设置此系统属性,您将能够在 ReportNG 中创建链接。

    System.setProperty("org.uncommons.reportng.escape-output", "false");               
    

    【讨论】:

      【解决方案2】:

      您可以使用下面的脚本并在您需要的每个类中调用该方法。

       public void screenCapture() throws IOException{
                System.setProperty("org.uncommons.reportng.escape-output", "false");
                File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
                String Path = "E:\\Automation\\testproject\\Screenshots\\";
                File screenshotName = new File(Path +driver.getTitle()+".png");
                //Now add screenshot to results by copying the file
                FileUtils.copyFile(scrFile, screenshotName);
                Reporter.log("<br>  <img src='"+screenshotName+"' height='100' width='100' /><br>");
                Reporter.log("<a href="+screenshotName+"></a>");
      
                {
      

      【讨论】:

      • 当我给出项目的相对路径(如“.././screenshots/screenshot1.jpg”)时,屏幕截图未附加。也没有图片链接
      【解决方案3】:

      当您截取屏幕截图并存储在某个位置后,您可以将其作为链接插入到测试报告中,因为 testng 报告是一个 html 文档。

      Reporter.log("<a href=" + URL+ ">click to open screenshot</a>");
      

      URL - 本地或网络驱动器上的位置

      【讨论】:

      • 然后我的记者显示:点击打开截图而不是可点击的链接。知道是什么原因造成的吗?
      猜你喜欢
      • 2019-09-24
      • 2013-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多