Problem with decoding of screenshot

100 views
Skip to first unread message

Pavel Stashevsky

unread,
Nov 12, 2009, 3:18:50 AM11/12/09
to webdriver
There is a problem with the transfer of screenshots from the server to
the client. When I do a screenshot on the server, then to encode in
base64 it is normal, after encoding and decoding on the client image
is not obtained such a need.

QA_manager

unread,
Nov 13, 2009, 9:37:19 AM11/13/09
to webdriver
Perhaps a bit more detail would make it easier for people to help
you.

1) What do you mean by 'server' and 'client' in this context?
2) How do you 'encode in base64'?
3) Can you post a screenshot before the encode/decode step on the
client, and then the same screenshot after encode/decode on the
client? Then (if the problem isn't obvious) please explain precisely
the nature of the problem.

Pavel Stashevsky

unread,
Nov 14, 2009, 1:19:19 AM11/14/09
to webdriver
Tests run on the remote webdriver server (RemoteWebdriver). When
ScreenshortException throws, then the server creates a screenshot,
which is encoded in base64 and a string is passed to the client.
public void onException(Throwable throwable, WebDriver driver) {
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 String(Base64.encodeBase64(outputStream.toByteArray
()), "UTF-8");

session.attachScreenshot(encoded);
} catch (Throwable e) {
System.out.println("e = " + e);
// Alright. No screen shot. Propogate the original exception
}
}

private void workAroundD3dBugInVista() {
if (Platform.getCurrent().is(Platform.WINDOWS)) {
System.setProperty("sun.java2d.d3d", "false");
}
}

On the client, this string is decoded and we get a screenshot of the
test, which was performed on a remote server.

public static void getReport(TestCase testCase, WebDriverException e)
throws Exception {
try {
WebDriver driver = testCase.driver;
Date date = new Date();
String timePattern = "HH.mm.ss_dd.MM.yyyy";
DateFormat dateFormatter = new SimpleDateFormat
(timePattern);
String dir = System.getProperty("user.home") + "/report" +
dateFormatter.format(date);
File folder = new File(dir);
folder.mkdir();
String img = new String(Base64.decodeBase64
(extractScreenShot(e).getBytes()));
FileWriter image = new FileWriter(new File(dir + "/" +
"screenshot" + ".png"));
image.write(img);
image.close();
} catch (Exception ex) {
throw ex;
}
}

public static String extractScreenShot(WebDriverException e) {
Throwable cause = e.getCause();
if (cause instanceof ScreenshotException) {
return ((ScreenshotException)
cause).getBase64EncodedScreenshot();
}
return null;
}

It was verified that the remote server creates a normal screenshot,
which breaks down during encoding, transmission and decoding.

QA_manager

unread,
Nov 16, 2009, 9:12:59 AM11/16/09
to webdriver
How did you verify that the screenshot is normal on the remote
server? Can you post a before and after sample so everyone can see
the problem?
Reply all
Reply to author
Forward
0 new messages