O'Reilly logo

Selenium 2 Testing Tools Beginner's Guide by David Burns

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – capturing images as base64 strings

Imagine that you want to take a screenshot on Selenium Grid. When you take the screenshot, you will not want it to be saved to the hard drive of the Selenium Grid node. You will want it to be moved back to where your tests are, especially if you are using it with a Continuous Integration Box.

  1. Open up Intellij and create a new Java test class.
  2. We will now add a new line for taking a screenshot:
    driver.get(http://book.theautomatedtester.co.uk);
    String screenshotBase64 = ((Screenshot)driver).getScreenshotAs(base64);
  3. If you set a breakpoint on the previous line, you will be able to see what the string looks like.

What just happened?

We have just managed to take a screenshot and have it returned as ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required