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 ...
Get Selenium Testing Tools Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.