Java Selenium 抓取网页的截图并添加报告
public void Screenshot() throws Throwable{
final byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png"); // ... and embed it in the report.
Thread.sleep(1000);
}
交替
public static void captureScreenShot(WebDriver ldriver){
// Take screenshot and store as a file format
File src= ((TakesScreenshot)ldriver).getScreenshotAs(OutputType.FILE);
try {
// now copy the screenshot to desired location using copyFile method
FileUtils.copyFile(src, new File("C:/selenium/"+System.currentTimeMillis()+".png"));
}
catch (IOException e)
{
System.out.println(e.getMessage());
}
}