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 – saving a screenshot to file

In this section we will have a look at how we can go about saving a file to disk. This is the most common thing that people do when saving screenshots. One thing to note is that if you are using RemoteWebDriver, this will save the file on the same machine as the Selenium Server.

  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);
    File savedImage = ((Screenshot)driver).getScreenshotAs(file);
  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 seen what is probably going to be the most common way to save screenshots when we take ...

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