Skip to content

Instantly share code, notes, and snippets.

@djangofan
Forked from neino3/Selenium2Example1Test.java
Last active December 11, 2015 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djangofan/4569761 to your computer and use it in GitHub Desktop.
Save djangofan/4569761 to your computer and use it in GitHub Desktop.
SeleniumRemote example using Augmenter for screenshot
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 SeleniumRemoteExample {
@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