Skip to content

Commit

Permalink
Fix Firefox proxy settings
Browse files Browse the repository at this point in the history
Set Firefox proxy settings using preferences, the PROXY capability is
not correctly used/parsed (at least in latest released version).
  • Loading branch information
thc202 committed Sep 11, 2017
1 parent 71bc03a commit 8c3ec21
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/main/java/org/mozilla/zest/core/v1/ZestClientLaunch.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,32 @@ public String invoke(ZestRuntime runtime) throws ZestClientFailException {
}

if ("Firefox".equalsIgnoreCase(this.browserType)) {
FirefoxOptions firefoxOptions = new FirefoxOptions();
if (isHeadless()) {
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.addArguments(HEADLESS_ARG);
firefoxOptions.addTo(cap);
}

if (!httpProxy.isEmpty()) {
String[] proxyData = httpProxy.split(":");
String proxyAddress = proxyData[0];
int proxyPort = Integer.parseInt(proxyData[1]);

// Some issues prevent the PROXY capability from being properly applied:
// https://bugzilla.mozilla.org/show_bug.cgi?id=1282873
// https://bugzilla.mozilla.org/show_bug.cgi?id=1369827
// For now set the preferences manually:
firefoxOptions.addPreference("network.proxy.type", 1);
firefoxOptions.addPreference("network.proxy.http", proxyAddress);
firefoxOptions.addPreference("network.proxy.http_port", proxyPort);
firefoxOptions.addPreference("network.proxy.ssl", proxyAddress);
firefoxOptions.addPreference("network.proxy.ssl_port", proxyPort);
firefoxOptions.addPreference("network.proxy.share_proxy_settings", true);
firefoxOptions.addPreference("network.proxy.no_proxies_on", "");
// And remove the PROXY capability:
cap.setCapability(CapabilityType.PROXY, (Object) null);
}
firefoxOptions.addTo(cap);

driver = new FirefoxDriver(cap);
} else if ("Chrome".equalsIgnoreCase(this.browserType)) {
if (isHeadless()) {
Expand Down

0 comments on commit 8c3ec21

Please sign in to comment.