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 class enhances the RemoteWebDriver by adding to it various interfaces including the TakesScreenshot interface.
driver = new Augmenter().augment(driver);
Later we can use the TakesScreenshot interface from RemoteWebDriver to capture the screenshot.