我遇到了一个问题,当在另一台机器上查看报告时,ExtentReports没有显示屏幕截图。当将图像保存到报表中时,我传递图像文件的绝对路径。想要查看报表的用户必须将report.html和错误屏幕截图文件夹复制到他们的D驱动器。只有他们才能看到截图。请建议另一种方式,以便用户可以复制这些文件到他们的任何位置,以便屏幕截图可以查看。
我的代码如下:
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, );发布于 2017-03-03 07:38:06
在截图中使用相对路径。保存html文件所在的屏幕截图。
发布于 2017-03-03 09:17:51
而不是相对路径。我发现,如果将图像转换为base64格式,会更容易。在这种情况下,我们只想共享.html文件。
TakesScreenshot ts =(TakesScreenshot)驱动程序; 字符串dest = ts.getScreenshotAs(OutputType.BASE64);返回"data:image/jpg;base64 64,“+ dest;
发布于 2019-06-04 13:09:55
我使用了ExtensionReportVersion2.40.2JAR,并以这种方式实现了我的reports文件夹的共享。路径在这里是相对的,报表将使用这些路径正确地呈现。希望这能有所帮助。我经历了许多联系,但实际上没有任何帮助,所以提出了这个逻辑。
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);https://stackoverflow.com/questions/42572908
复制相似问题