0

I'm wondering what the advantages/disadvantages of one over the other are?

I'm running against Selenium Server on a headless remote instance with Xvfb acting as the display.

Both methods work fine and the resulting screen capture file (if I convert the base64 one and save it as an image file) are identical file size and look identical.

So why would I want to use/not use one over the other?

ColinMcC
  • 258
  • 5
  • 13
  • 1
    with base64 you get an image that is safe to send over network, while saving to file gives you, well, a file, which is not safe to sendover a socket without encoding it. – Tymoteusz Paul Aug 29 '14 at 09:49
  • Thanks. Can you expand on the "not safe" part of the file type capture? Having tried it against a remote instance, the image file in question came back to me quite happily? Will go with the base64 version, but am still curious why the other is not regarded as safe. Is it a security thing? Or a "likely to get corrupted" thing? – ColinMcC Aug 29 '14 at 09:52

1 Answers1

3

With the get_screenshot_as_file, the screenshot get saves into a binary file, while with get_screenshot_as_base64 this will return you base64 encoded version of that screenshot.

So, why would anyone use the base64 version? The whole idea behind base64 is that it allows you to create ASCII representation of binary data, which will increase the data size but will also allow you to actually work with it. For example if you've tried to send over a stream of binary data to a socket, without encoding it then unless server was prepared to handle binary data, the result is hard to predict.

As a result of that the data transferred may be malformed, cut the transfer early and cause many other results that are almost impossible to predict. For example if you were to run a very simple socket server that just prints out everything as it receives to std::out, receiving a binary file would most likely corrupt your console terminal (you can try it on your very own Linux box).

Of course if the server is designed to receive and handle binary data then this will not be an issue, but most often the server-end will interpret user input as string which makes using base64 a wise choice.

Tymoteusz Paul
  • 2,732
  • 17
  • 20
  • Thanks again for the detailed explanation. I'll stick with the base64 version to be on the safe side. – ColinMcC Aug 29 '14 at 10:40