Skip to content

Instantly share code, notes, and snippets.

@freynaud
Created June 2, 2011 11:35
Show Gist options
  • Save freynaud/1004271 to your computer and use it in GitHub Desktop.
Save freynaud/1004271 to your computer and use it in GitHub Desktop.
running chrome
import java.io.File;
import java.net.URL;
import org.openqa.selenium.OutputType;
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;
import org.openqa.selenium.server.RemoteControlConfiguration;
import org.openqa.selenium.server.SeleniumServer;
public class Venkat {
public static void main(String[] args) throws Exception {
System.setProperty("webdriver.chrome.driver","c:\\tmp\\chromedriver.exe");
int port = 4444;
RemoteControlConfiguration config = new RemoteControlConfiguration();
config.setPort(port);
SeleniumServer server = new SeleniumServer(config);
server.boot();
WebDriver driver = null;
try {
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), DesiredCapabilities.chrome());
driver.get("http://google.com");
Thread.sleep(5000);
Augmenter a = new Augmenter(); driver = a.augment(driver);
File tmp = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
tmp.renameTo(new File("c:\\tmp\\ss.png"));
System.out.println(driver.getTitle());
} finally {
if (driver != null) {
driver.quit();
}
server.stop();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment