首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >硒Webdriver驱动程序中的ExtentReports

硒Webdriver驱动程序中的ExtentReports
EN

Stack Overflow用户
提问于 2017-03-03 07:18:01
回答 4查看 2.3K关注 0票数 1

我遇到了一个问题,当在另一台机器上查看报告时,ExtentReports没有显示屏幕截图。当将图像保存到报表中时,我传递图像文件的绝对路径。想要查看报表的用户必须将report.html和错误屏幕截图文件夹复制到他们的D驱动器。只有他们才能看到截图。请建议另一种方式,以便用户可以复制这些文件到他们的任何位置,以便屏幕截图可以查看。

我的代码如下:

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

String dest = "D:\\ErrorScreenshots\\"+screenShotName+System.currentTimeMillis()+".png";
File destination = new File("D:\\ErrorScreenshots\\"+screenShotName+System.currentTimeMillis()+".png");
FileUtils.copyFile(source, destination);    
//FileUtils.copyFile(source, );
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2017-03-03 07:38:06

在截图中使用相对路径。保存html文件所在的屏幕截图。

票数 1
EN

Stack Overflow用户

发布于 2017-03-03 09:17:51

而不是相对路径。我发现,如果将图像转换为base64格式,会更容易。在这种情况下,我们只想共享.html文件。

TakesScreenshot ts =(TakesScreenshot)驱动程序; 字符串dest = ts.getScreenshotAs(OutputType.BASE64);返回"data:image/jpg;base64 64,“+ dest;

票数 2
EN

Stack Overflow用户

发布于 2019-06-04 13:09:55

我使用了ExtensionReportVersion2.40.2JAR,并以这种方式实现了我的reports文件夹的共享。路径在这里是相对的,报表将使用这些路径正确地呈现。希望这能有所帮助。我经历了许多联系,但实际上没有任何帮助,所以提出了这个逻辑。

代码语言:javascript
复制
public String capture() throws IOException {    
    try{
        //take screenshot and save it in a file
        File sourceFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
        //copy the file to the required path
        File destinationFile = new File(System.getProperty("user.dir")+"/reports/image_" + System.currentTimeMillis()+ ".png");
        FileHandler.copy(sourceFile, destinationFile);  
        String[] relatvePath = destinationFile.toString().split("reports");
        screenshotPath = ".\\" + relatvePath[1];
    }
    catch(Exception e){
        //if it fails to take screenshot then this block will execute
        System.out.println("Failure to take screenshot "+e);
    }
    return screenshotPath;
}

        test.log(LogStatus.FAIL, Constants.REPORT_ERROR, test.addScreenCapture(capture()) + Constants.REPORT_ERROR_STATUS);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42572908

复制
相关文章

相似问题

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