Skip to content

Commit

Permalink
Attempt to reduce test crashes for chromedriver tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Mar 15, 2017
1 parent 78fede9 commit d8132d6
Showing 1 changed file with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,38 @@
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;

/**
* Customized RemoteWebDriver that will communicate with a service that lives and dies with the
* entire test suite. We do not use {@link org.openqa.selenium.chrome.ChromeDriver} since that starts and stops the service
* with each instance (and that is too expensive for our purposes).
*/
public class TestChromeDriver extends RemoteWebDriver {
private final static Logger LOG = Logger.getLogger(TestChromeDriver.class.getName());

private static ChromeDriverService service;

public TestChromeDriver() {
super(chromeWithCustomCapabilities(null));
}

public TestChromeDriver(Capabilities capabilities) {
public TestChromeDriver(Capabilities capabilities) throws IOException {
super(getServiceUrl(), chromeWithCustomCapabilities(capabilities));
}

private static URL getServiceUrl() {
private static URL getServiceUrl() throws IOException {
if (service == null && !SauceDriver.shouldUseSauce()) {
service = ChromeDriverService.createDefaultService();
Path logFile = Files.createTempFile("chromedriver", ".log");
service = new ChromeDriverService.Builder()
.withVerbose(true)
.withLogFile(logFile.toFile())
.build();
LOG.info("chromedriver will log to " + logFile);
try {
service.start();
} catch (IOException e) {
Expand All @@ -68,7 +80,7 @@ public void run() {
private static DesiredCapabilities chromeWithCustomCapabilities(
Capabilities originalCapabilities) {
ChromeOptions options = new ChromeOptions();
options.addArguments("disable-extensions");
options.addArguments("disable-extensions", "disable-infobars", "disable-breakpad");
String chromePath = System.getProperty("webdriver.chrome.binary");
if (chromePath != null) {
options.setBinary(new File(chromePath));
Expand Down

0 comments on commit d8132d6

Please sign in to comment.