2

Is it possible to take screenshots using selenium grid 2? The RemoteWebDriver class does not implement the TakesScreenshot interface.

Mark

Mark Micallef
  • 1,051
  • 2
  • 12
  • 25

2 Answers2

5

The RemoteWebDriver must be augmented before you can use the screenshot capability. As you have no doubt already found, attempting to cast without augmenting results in an exception.

WebDriver driver = new RemoteWebDriver( ... );
driver           = new Augmenter().augment( driver );
( (TakesScreenshot)driver ).getScreenshotAs( ... );
Mike Kwan
  • 24,123
  • 12
  • 63
  • 96
0

You would need to write a wrapper class that extends RemoteWebDriver and implement TakeScreenshot interface something like below in java.

public class ScreenShotRemoteWebDriver extends RemoteWebDriver implements TakesScreenshot 
{ 
    public ScreenShotRemoteWebDriver(URL url, DesiredCapabilities dc) { 
        super(url, dc); 
    } 
    @Override
    public <X> X getScreenshotAs(OutputType<X> target) throws WebDriverException { 
        if ((Boolean)getCapabilities().getCapability(CapabilityType.TAKES_SCREENSHOT)) {
            return target.convertFromBase64Png(execute(DriverCommand.SCREENSHOT).getValue().toString()); 
        } 
        return null; 
    } 
}
nilesh
  • 14,131
  • 7
  • 65
  • 79