Search in sources :

Example 1 with Base64Encoder

use of org.openqa.selenium.internal.Base64Encoder in project zeppelin by apache.

the class ScreenCaptureHtmlUnitDriver method getScreenshotAs.

@Override
@SuppressWarnings("unchecked")
public <X> X getScreenshotAs(OutputType<X> target) throws WebDriverException {
    byte[] archive = new byte[0];
    try {
        archive = downloadCssAndImages(getWebClient(), (HtmlPage) getCurrentWindow().getEnclosedPage());
    } catch (Exception e) {
        LOGGER.error("Exception in ScreenCaptureHtmlUnitDriver while getScreenshotAs ", e);
    }
    if (target.equals(OutputType.BASE64)) {
        return target.convertFromBase64Png(new Base64Encoder().encode(archive));
    }
    if (target.equals(OutputType.FILE)) {
        File f = new File("screen.tmp");
        try {
            FileOutputStream scr = new FileOutputStream(f);
            scr.write(archive);
            scr.close();
        } catch (IOException e) {
            throw new WebDriverException(e);
        }
        return (X) f;
    }
    return (X) archive;
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) WebDriverException(org.openqa.selenium.WebDriverException) IOException(java.io.IOException) Base64Encoder(org.openqa.selenium.internal.Base64Encoder) WebDriverException(org.openqa.selenium.WebDriverException)

Aggregations

HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 WebDriverException (org.openqa.selenium.WebDriverException)1 Base64Encoder (org.openqa.selenium.internal.Base64Encoder)1