Search in sources :

Example 1 with ScreenshotException

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());
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) ScreenshotException(org.openqa.selenium.remote.ScreenshotException) File(java.io.File) TakesScreenshot(org.openqa.selenium.TakesScreenshot)

Aggregations

File (java.io.File)1 TakesScreenshot (org.openqa.selenium.TakesScreenshot)1 WebDriver (org.openqa.selenium.WebDriver)1 ScreenshotException (org.openqa.selenium.remote.ScreenshotException)1