public String saveScreenshot(String filename, long timeout, boolean includeImage,
List<String> hashes) {
assertElementNotStale();
Canvas canvas = buildCanvas();
ScreenCaptureReply reply =
exec.screenWatcher(canvas, timeout, includeImage, hashes);
if (includeImage && reply.getPng() != null) {
FileChannel stream;
try {
stream = new FileOutputStream(filename).getChannel();
stream.write(ByteBuffer.wrap(reply.getPng()));
stream.close();
} catch (IOException e) {
throw new WebDriverException("Failed to write file: " + e.getMessage(), e);
}
}
return reply.getMd5();
}