Java 类org.openqa.selenium.internal.Base64Encoder 实例源码

项目:grid-refactor-remote-server    文件:SnapshotScreenListener.java   
@Override
public void onException(Throwable throwable, WebDriver driver) {
  if (Platform.getCurrent().is(Platform.ANDROID)) {
    // Android Java APIs do not support java.awt
    return;
  }
  String encoded;
  try {
    workAroundD3dBugInVista();

    Rectangle size = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
    BufferedImage image = new Robot().createScreenCapture(size);

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    ImageIO.write(image, "png", outputStream);

    encoded = new Base64Encoder().encode(outputStream.toByteArray());

    session.attachScreenshot(encoded);
  } catch (Throwable e) {
    // Alright. No screen shot. Propogate the original exception
  }
}
项目:selendroid    文件:CaptureScreenshot.java   
@Override
public Response handleRequest(HttpRequest request, JSONObject payload) throws JSONException {
  byte[] rawPng;
  try {
    rawPng = getSelendroidDriver(request).takeScreenshot(getSessionId(request));
  } catch (AndroidDeviceException e) {
    log.log(Level.SEVERE, "Cannot take screenshot", e);
    return new SelendroidResponse(getSessionId(request), StatusCode.UNKNOWN_ERROR, e);
  }
  String base64Png = new Base64Encoder().encode(rawPng);

  return new SelendroidResponse(getSessionId(request), base64Png);
}