Example usage for org.openqa.selenium OutputType convertFromBase64Png

List of usage examples for org.openqa.selenium OutputType convertFromBase64Png

Introduction

In this page you can find the example usage for org.openqa.selenium OutputType convertFromBase64Png.

Prototype

T convertFromBase64Png(String base64Png);

Source Link

Document

Convert the given base64 png to a requested format.

Usage

From source file:com.elastica.driver.ScreenShotRemoteWebDriver.java

License:Apache License

public <X> X getScreenshotAs(final OutputType<X> target) throws WebDriverException {
    if ((Boolean) getCapabilities().getCapability(CapabilityType.TAKES_SCREENSHOT)) {
        String output = execute(DriverCommand.SCREENSHOT).getValue().toString();
        return target.convertFromBase64Png(output);
    }/*from   w ww .j a v  a 2  s .c  o m*/

    return null;
}

From source file:com.google.android.testing.nativedriver.client.AndroidNativeDriver.java

License:Apache License

/**
 * {@inheritDoc}/*  w w  w.  j a v a2s  .c  o m*/
 *
 * <p>Unlike most {@link RemoteWebDriver} operations, this implementation
 * does not send a request to the remote server. The screenshot is taken by
 * using ADB on the driver client side to query the device.
 *
 * @throws AdbException if an error occurred while driving the device through
 *         the {@code adb} tool
 */
@Override
public <X> X getScreenshotAs(OutputType<X> target) throws AdbException {
    AdbConnection adb = validateAdbConnection();
    FrameBufferFormat format = FrameBufferFormat.ofDevice(adb);

    BufferedImage screenImage = new BufferedImage(format.getXResolution(), format.getYResolution(),
            BufferedImage.TYPE_INT_ARGB);

    Process pullFrameBuffer = adb.pullFile(FrameBufferFormat.FB_DEVICEFILE);
    InputStream frameBufferStream = pullFrameBuffer.getInputStream();
    format.copyFrameBufferToImage(frameBufferStream, screenImage);

    AdbConnection.exhaustProcessOutput(frameBufferStream);
    Closeables.closeQuietly(frameBufferStream);
    AdbConnection.confirmExitValueIs(0, pullFrameBuffer);

    String base64Png = imageToBase64Png(screenImage);

    return target.convertFromBase64Png(base64Png);
}

From source file:com.jaliansystems.customiSE.driver.CustomiSEDriver.java

License:Apache License

public <X> X getScreenshotAs(OutputType<X> target) {
    // Get the screenshot as base64.
    String base64 = execute(DriverCommand.SCREENSHOT).getValue().toString();

    // ... and convert it.
    return target.convertFromBase64Png(base64);
}

From source file:com.lohika.alp.selenium.RemoteWebDriverTakeScreenshotFix.java

License:Open Source License

@Override
public <X> X getScreenshotAs(OutputType<X> target) throws WebDriverException {
    // Get the screenshot as base64.
    String base64 = execute(DriverCommand.SCREENSHOT).getValue().toString();
    // ... and convert it.
    return target.convertFromBase64Png(base64);
}

From source file:com.qmetry.qaf.automation.ui.webdriver.QAFExtendedWebDriver.java

License:Open Source License

@Override
public <X> X getScreenshotAs(OutputType<X> target) throws WebDriverException {
    Object takeScreenshot = getCapabilities().getCapability(CapabilityType.TAKES_SCREENSHOT);
    if (null == takeScreenshot || (Boolean) takeScreenshot) {
        String base64Str = execute(DriverCommand.SCREENSHOT).getValue().toString();
        return target.convertFromBase64Png(base64Str);
    }//from  w ww. ja  v a 2  s  . c o m
    return null;
}

From source file:com.qmetry.qaf.automation.ui.webdriver.QAFExtendedWebDriver.java

License:Open Source License

public <T> T extractScreenShot(WebDriverException e, OutputType<T> target) {
    if (e.getCause() instanceof ScreenshotException) {
        String base64Str = ((ScreenshotException) e.getCause()).getBase64EncodedScreenshot();
        return target.convertFromBase64Png(base64Str);
    }/* w w  w  .  j  ava2s.  c  om*/
    return null;
}

From source file:io.selendroid.SelendroidDriver.java

License:Apache License

/**
 * {@inheritDoc}/*from   ww  w  . j a v  a2  s.  c  om*/
 */
@Override
public <X> X getScreenshotAs(OutputType<X> target) throws WebDriverException {
    String base64 = execute(org.openqa.selenium.remote.DriverCommand.SCREENSHOT).getValue().toString();
    return target.convertFromBase64Png(base64);
}

From source file:jp.co.nssol.h5.test.selenium.base.DriverFactory.java

License:Apache License

/**
 * IPhoneDriver???//from  w w  w .j  a va2  s  .com
 *
 * @return IPhoneDriver
 */
private static WebDriver setupIPhoneDriver() {
    String serverPath = SettingsReader.getProperty(PKEY_IPHONE_SERVER_PATH);
    WebDriver driver = null;

    try {
        driver = new IPhoneDriver(serverPath) {
            /**
             * IPhoneDriver#getScreenshotAs()???????????
             */
            @Override
            public <X> X getScreenshotAs(OutputType<X> target) {
                String base64 = (String) execute("screenshot").getValue();
                return target.convertFromBase64Png(base64);
            }

            @Override
            public String toString() {
                return "iPhone";
            }
        };
    } catch (Exception e) {
        e.printStackTrace();
    }

    return driver;
}

From source file:org.fluentlenium.unit.ScreenshotTest.java

License:Apache License

public <X> X getScreenshotAs(OutputType<X> xOutputType) throws WebDriverException {
    return xOutputType.convertFromBase64Png("test");
}

From source file:org.openqa.selendroid.SelendroidDriver.java

License:Open Source License

/**
 * {@inheritDoc}// ww  w. j a  v a 2 s .  co  m
 */
@Override
public <X> X getScreenshotAs(OutputType<X> target) throws WebDriverException {
    String base64 = execute(DriverCommand.SCREENSHOT).getValue().toString();
    return target.convertFromBase64Png(base64);
}