Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JAffleck/2771e1593a747a59c2b9dbcf516c2c47 to your computer and use it in GitHub Desktop.
Save JAffleck/2771e1593a747a59c2b9dbcf516c2c47 to your computer and use it in GitHub Desktop.
how to take screen shot by using Selenium2 Grid
import java.io.File;
import java.io.IOException;
import java.net.URL;
import org.apache.commons.io.FileUtils;
import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.Platform;
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 Selenium2Example1Test {
@Test
public void test() throws IOException {
// http://stackoverflow.com/questions/7080305/selenium2-taking-screenshots-with-selenium-grid-2
// Instantiate a webDriver implementation
// WebDriver webdriver = new FirefoxDriver();
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName("firefox");
// capabilities.setVersion("7");
capabilities.setPlatform(Platform.MAC);
WebDriver webdriver = new RemoteWebDriver(new URL(
"http://localhost:4444/wd/hub"), capabilities);
webdriver = new Augmenter().augment(webdriver);
webdriver.get("https://github.com");
File srcFile = ((TakesScreenshot) webdriver)
.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(srcFile, new File("./test003.png"));
Assert.assertEquals("GitHub · Social Coding", webdriver.getTitle());
webdriver.quit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment