O'Reilly logo

Selenium Testing Tools Cookbook by Unmesh Gundecha

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

Capturing screenshots with RemoteWebDriver/Grid

While running tests with RemoteWebDriver or Grid it is not possible to take the screenshots, as the TakesScreenshot interface is not implemented in RemoteWebDriver.

However, we can use the Augmenter class which adds the TakesScreenshot interface to the remote driver instance.

In this recipe, we will use the Augmenter class to capture a screenshot from RemoteWebDriver.

Getting ready

Create a test which uses RemoteWebDriver.

How to do it...

Add the following code to the test using RemoteWebDriver:

driver = new Augmenter().augment(driver);
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));

How it works...

The Augmenter ...

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