Skip to content

Instantly share code, notes, and snippets.

@zevnull
Created September 20, 2013 08:23
Show Gist options
  • Save zevnull/6634682 to your computer and use it in GitHub Desktop.
Save zevnull/6634682 to your computer and use it in GitHub Desktop.
take screenshot using Remote webdriver
public class ScreenShotRemoteWebDriver extends RemoteWebDriver implements TakesScreenshot {
public ScreenShotRemoteWebDriver(URL url, DesiredCapabilities capabilities) {
super(url, capabilities);
}
public <X> X getScreenshotAs(OutputType<X> target) throws WebDriverException {
if ((Boolean)getCapabilities().getCapability(CapabilityType.TAKES_SCREENSHOT)) {
return target.convertFromBase64Png(execute(DriverCommand.SCREENSHOT).getValue().to­String());
}
return null;
}}
******How to use***************
URL url=new URL("http://"+remoteServer+":"+remotePort+"/wd/hub");
capabilities.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
capabilities.setJavascriptEnabled(true);
capabilities.setBrowserName(browser);
driver = new ScreenShotRemoteWebDriver(url, capabilities);
driver.get("http://www.google.com");
File temp =
((ScreenShotRemoteWebDriver)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(temp, new File("c:/copy/my/picturehere.png"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment