2017-03-03 87 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 ;