2017-03-03 54 views
1

我在ExtentReports未在其他机器上查看报告时显示屏幕截图。将图像保存到报告中时,我传递图像文件的绝对路径。想要查看报告的用户必须将report.html和Errorscreenshot文件夹复制到他们的D驱动器。然后只有他们可以看到截图。请建议另一种方式,以便用户可以将这些文件复制到他们的任何位置,以便可以查看屏幕截图。Selenium Webdriver的范围报告

我的代码如下:

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,); 

回答

1

使用你的截图相对路径。将您的截图保存在您的html文件所在的位置。

+0

如何使用上面的代码 – Vishnu

1

使用相对的截图如下路径:

String path = System.getProperty("user.dir")+"\\ErrorScreenshots\\"+screenShotName+System.currentTimeMillis()+".png"; 
File destination = new File(path); 
+0

它的工作相对路径。我添加了这样的 String dest =“。\\ ErrorScreenshots \\”+ screenShotName + System.currentTimeMillis()+“。png”; File destination = new File(“。\\ ErrorScreenshots \\”+ screenShotName + System.currentTimeMillis()+“。png”); – Vishnu

1

而是相对路径。如果图像转换为base64格式,我发现它更容易。在这种情况下,我们只想共享.html文件。 TakesScreenshot ts =(TakesScreenshot)驱动程序;

TakesScreenshot ts =(TakesScreenshot)driver;

String dest = ts.getScreenshotAs(OutputType.BASE64); 

    return "data:image/jpg;base64, " + dest ;