Skip to content

Commit

Permalink
Add support for proxy username and proxy password
Browse files Browse the repository at this point in the history
  • Loading branch information
Ardesco committed Apr 22, 2019
1 parent 9305dcf commit 9d37154
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ You can also specify a proxy to use
- -DproxyEnabled=true
- -DproxyHost=localhost
- -DproxyPort=8080
- -DproxyUsername=fred
- -DproxyPassword=Password123

If the tests fail screenshots will be saved in ${project.basedir}/target/screenshots

Expand Down
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
<proxyEnabled>false</proxyEnabled>
<proxyHost/>
<proxyPort/>
<proxyUsername/>
<proxyPassword/>
</properties>

<dependencies>
Expand Down Expand Up @@ -160,6 +162,8 @@
<proxyEnabled>${proxyEnabled}</proxyEnabled>
<proxyHost>${proxyHost}</proxyHost>
<proxyPort>${proxyPort}</proxyPort>
<proxyUsername>${proxyUsername}</proxyUsername>
<proxyPassword>${proxyPassword}</proxyPassword>
<headless>${headless}</headless>

<!--Set properties passed in by the driver binary downloader-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class DriverFactory {
private final boolean proxyEnabled = Boolean.getBoolean("proxyEnabled");
private final String proxyHostname = System.getProperty("proxyHost");
private final Integer proxyPort = Integer.getInteger("proxyPort");
private final String proxyUsername = System.getProperty("proxyUsername");
private final String proxyPassword = System.getProperty("proxyPassword");
private final String proxyDetails = String.format("%s:%d", proxyHostname, proxyPort);

public DriverFactory() {
Expand Down Expand Up @@ -74,6 +76,12 @@ private void instantiateWebDriver(DriverType driverType) throws MalformedURLExce
proxy.setProxyType(MANUAL);
proxy.setHttpProxy(proxyDetails);
proxy.setSslProxy(proxyDetails);
if (!proxyUsername.isEmpty()) {
proxy.setSocksUsername(proxyUsername);
}
if (!proxyPassword.isEmpty()) {
proxy.setSocksPassword(proxyPassword);
}
desiredCapabilities.setCapability(PROXY, proxy);
}

Expand Down

0 comments on commit 9d37154

Please sign in to comment.