Skip to content

Instantly share code, notes, and snippets.

@hidepin
Last active March 19, 2016 09:54
Show Gist options
  • Save hidepin/3aed92499e432e4e752b to your computer and use it in GitHub Desktop.
Save hidepin/3aed92499e432e4e752b to your computer and use it in GitHub Desktop.
selenium remotewebdriver screenshot
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.Augmenter;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class NavigateToAUrl {
public static void main(String[] args) {
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
RemoteWebDriver remoteWD = null;
try {
remoteWD = new RemoteWebDriver(new URL("http://192.168.137.225:4444/wd/hub"), capabilities);
remoteWD.get("file://C:/selenium/Chapter 2/HTML/Selectable.html");
Thread.sleep(1000);
WebDriver augmentedDriver = new Augmenter().augment(remoteWD);
File screenshot = ((TakesScreenshot)augmentedDriver)
.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenshot, new File("C:/work/test.png"));
/*
File screenshot = (File) ((TakesScreenshot)remoteWD)
.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenshot, new File("C:/work/test.png"));
*/
Thread.sleep(2000);
remoteWD.quit();
} catch (InterruptedException | IOException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment