首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >屏幕截图不显示在范围报告中

屏幕截图不显示在范围报告中
EN

Stack Overflow用户
提问于 2021-06-04 19:44:00
回答 1查看 50关注 0票数 0

屏幕截图将被拍摄并存储在文件夹中。但对于失败的测试,它不显示。显示为损坏的图像。

Java代码:

代码语言:javascript
复制
    public synchronized void onTestFailure(ITestResult result) {
                System.out.println((result.getMethod().getMethodName() + " failed!"));
                test.get().fail(MarkupHelper.createLabel(result.getName()+ " - Test failed due to below issue/error: ", ExtentColor.RED));
                test.get().fail(result.getThrowable());
                
                //Take screenshot and allow automatic saving of media files relative to the report
                //Extentreports log and screenshot operations for failed tests.
                try {
                    File src=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
    //          String base64Screenshot = "data:image/png;base64,"+((TakesScreenshot)driver).getScreenshotAs(OutputType.BASE64);
                    String path=prop.getProperty("Screenshot_Folder")+System.currentTimeMillis()+".png";
                    File destination=new File(path);
                    FileUtils.copyFile(src, destination);
                    
                    test.get().fail("Below is Screen Shot of Error Page/Pop-up: ", MediaEntityBuilder.createScreenCaptureFromPath(path).build());
                    //test.get().fail("Below is Screen Shot of Error Page/Pop-up: ", MediaEntityBuilder.createScreenCaptureFromBase64String(base64Screenshot).build());
                } catch (Exception e) {
                    e.printStackTrace();
                    System.out.println("Screen-capture has been taken but not attached to Extent report");
                }
    
            }

下面是属性文件。

代码语言:javascript
复制
AutomationReport_Folder = D://Shared//V1core_automation
ExtentReport_Folder = D://Shared//V1core_automation//ExtentReports//
Screenshot_Folder = D://Shared//V1core_automation//ExtentReports//Screenshots//

一种截图方法

公共静态字符串驱动程序(WebDriver GetScreenshot){

代码语言:javascript
复制
        TakesScreenshot ts=(TakesScreenshot) driver;
        File src=ts.getScreenshotAs(OutputType.FILE);

        String path=System.getProperty("user.dir")+"/Screenshots/"+System.currentTimeMillis()+".png";

        File destination=new File(path);

        try 
        {
            FileUtils.copyFile(src, destination);
        } catch (IOException e) 
        {
            System.out.println("Capture Failed "+e.getMessage());
        }

        return path;

    }
EN

回答 1

Stack Overflow用户

发布于 2021-06-21 15:49:17

在代码中替换下面这一行:

代码语言:javascript
复制
test.get().fail("Below is Screen Shot of Error Page/Pop-up: ", MediaEntityBuilder.createScreenCaptureFromPath(path).build());

使用

代码语言:javascript
复制
MediaEntityBuilder.addScreenCaptureFromPath(path, result.getMethod().getMethodName());

看看它是如何工作的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67836644

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档