use of org.openqa.selenium.remote.ScreenshotException in project blueocean-plugin by jenkinsci.
the class ATHJUnitRunner method writeScreenShotCause.
private void writeScreenShotCause(Throwable t, Object test, FrameworkMethod method) throws IOException {
WebDriver driver = injector.getInstance(WebDriver.class);
File file = new File("target/screenshots/" + test.getClass().getName() + "_" + method.getName() + ".png");
Throwable cause = t.getCause();
boolean fromException = false;
while (cause != null) {
if (cause instanceof ScreenshotException) {
ScreenshotException se = ((ScreenshotException) cause);
byte[] screenshot = Base64.getMimeDecoder().decode(se.getBase64EncodedScreenshot());
Files.createParentDirs(file);
Files.write(screenshot, file);
logger.info("Wrote screenshot to " + file.getAbsolutePath());
fromException = true;
break;
} else {
cause = cause.getCause();
}
}
if (!fromException) {
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, file);
logger.info("Wrote screenshot to " + file.getAbsolutePath());
}
}
Aggregations