Skip to content

Commit 97a784f

Browse files
committed
Add methods that delegate calls to superclass to make driver services typesafe and chainable
1 parent d69a533 commit 97a784f

File tree

3 files changed

+183
-0
lines changed

3 files changed

+183
-0
lines changed

java/client/src/org/openqa/selenium/chrome/ChromeDriverService.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020
import com.google.common.collect.ImmutableList;
2121
import com.google.common.collect.ImmutableMap;
2222

23+
import org.openqa.selenium.Beta;
2324
import org.openqa.selenium.WebDriverException;
2425
import org.openqa.selenium.remote.service.DriverService;
2526

2627
import java.io.File;
2728
import java.io.IOException;
29+
import java.util.Map;
2830

2931
/**
3032
* Manages the life and death of a chromedriver server.
@@ -90,6 +92,65 @@ public static class Builder extends DriverService.Builder<ChromeDriverService> {
9092
private boolean verbose = Boolean.getBoolean(CHROME_DRIVER_VERBOSE_LOG_PROPERTY);
9193
private boolean silent = Boolean.getBoolean(CHROME_DRIVER_SILENT_OUTPUT_PROPERTY);
9294

95+
/**
96+
* Sets which driver executable the builder will use.
97+
*
98+
* @param file The executable to use.
99+
* @return A self reference.
100+
*/
101+
public Builder usingDriverExecutable(File file) {
102+
super.usingDriverExecutable(file);
103+
return this;
104+
}
105+
106+
/**
107+
* Sets which port the driver server should be started on. A value of 0 indicates that any
108+
* free port may be used.
109+
*
110+
* @param port The port to use; must be non-negative.
111+
* @return A self reference.
112+
*/
113+
public Builder usingPort(int port) {
114+
super.usingPort(port);
115+
return this;
116+
}
117+
118+
/**
119+
* Configures the driver server to start on any available port.
120+
*
121+
* @return A self reference.
122+
*/
123+
public Builder usingAnyFreePort() {
124+
super.usingAnyFreePort();
125+
return this;
126+
}
127+
128+
/**
129+
* Defines the environment for the launched driver server. These
130+
* settings will be inherited by every browser session launched by the
131+
* server.
132+
*
133+
* @param environment A map of the environment variables to launch the
134+
* server with.
135+
* @return A self reference.
136+
*/
137+
@Beta
138+
public Builder withEnvironment(Map<String, String> environment) {
139+
super.withEnvironment(environment);
140+
return this;
141+
}
142+
143+
/**
144+
* Configures the driver server to write log to the given file.
145+
*
146+
* @param logFile A file to write log to.
147+
* @return A self reference.
148+
*/
149+
public Builder withLogFile(File logFile) {
150+
super.withLogFile(logFile);
151+
return this;
152+
}
153+
93154
/**
94155
* Configures the driver server verbosity.
95156
*

java/client/src/org/openqa/selenium/ie/InternetExplorerDriverService.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020
import com.google.common.collect.ImmutableList;
2121
import com.google.common.collect.ImmutableMap;
2222

23+
import org.openqa.selenium.Beta;
2324
import org.openqa.selenium.WebDriverException;
2425
import org.openqa.selenium.remote.service.DriverService;
2526

2627
import java.io.File;
2728
import java.io.IOException;
29+
import java.util.Map;
2830

2931
/**
3032
* Manages the life and death of an IEDriverServer.
@@ -106,6 +108,65 @@ public static class Builder extends DriverService.Builder<InternetExplorerDriver
106108
private Boolean forceCreateProcess = null;
107109
private String ieSwitches = null;
108110

111+
/**
112+
* Sets which driver executable the builder will use.
113+
*
114+
* @param file The executable to use.
115+
* @return A self reference.
116+
*/
117+
public Builder usingDriverExecutable(File file) {
118+
super.usingDriverExecutable(file);
119+
return this;
120+
}
121+
122+
/**
123+
* Sets which port the driver server should be started on. A value of 0 indicates that any
124+
* free port may be used.
125+
*
126+
* @param port The port to use; must be non-negative.
127+
* @return A self reference.
128+
*/
129+
public Builder usingPort(int port) {
130+
super.usingPort(port);
131+
return this;
132+
}
133+
134+
/**
135+
* Configures the driver server to start on any available port.
136+
*
137+
* @return A self reference.
138+
*/
139+
public Builder usingAnyFreePort() {
140+
super.usingAnyFreePort();
141+
return this;
142+
}
143+
144+
/**
145+
* Defines the environment for the launched driver server. These
146+
* settings will be inherited by every browser session launched by the
147+
* server.
148+
*
149+
* @param environment A map of the environment variables to launch the
150+
* server with.
151+
* @return A self reference.
152+
*/
153+
@Beta
154+
public Builder withEnvironment(Map<String, String> environment) {
155+
super.withEnvironment(environment);
156+
return this;
157+
}
158+
159+
/**
160+
* Configures the driver server to write log to the given file.
161+
*
162+
* @param logFile A file to write log to.
163+
* @return A self reference.
164+
*/
165+
public Builder withLogFile(File logFile) {
166+
super.withLogFile(logFile);
167+
return this;
168+
}
169+
109170
/**
110171
* Configures the logging level for the driver server.
111172
*

java/client/src/org/openqa/selenium/opera/OperaDriverService.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020
import com.google.common.collect.ImmutableList;
2121
import com.google.common.collect.ImmutableMap;
2222

23+
import org.openqa.selenium.Beta;
2324
import org.openqa.selenium.WebDriverException;
2425
import org.openqa.selenium.remote.service.DriverService;
2526

2627
import java.io.File;
2728
import java.io.IOException;
29+
import java.util.Map;
2830

2931
/**
3032
* Manages the life and death of a operadriver server.
@@ -90,6 +92,65 @@ public static class Builder extends DriverService.Builder<OperaDriverService> {
9092
private boolean verbose = Boolean.getBoolean(OPERA_DRIVER_VERBOSE_LOG_PROPERTY);
9193
private boolean silent = Boolean.getBoolean(OPERA_DRIVER_SILENT_OUTPUT_PROPERTY);
9294

95+
/**
96+
* Sets which driver executable the builder will use.
97+
*
98+
* @param file The executable to use.
99+
* @return A self reference.
100+
*/
101+
public Builder usingDriverExecutable(File file) {
102+
super.usingDriverExecutable(file);
103+
return this;
104+
}
105+
106+
/**
107+
* Sets which port the driver server should be started on. A value of 0 indicates that any
108+
* free port may be used.
109+
*
110+
* @param port The port to use; must be non-negative.
111+
* @return A self reference.
112+
*/
113+
public Builder usingPort(int port) {
114+
super.usingPort(port);
115+
return this;
116+
}
117+
118+
/**
119+
* Configures the driver server to start on any available port.
120+
*
121+
* @return A self reference.
122+
*/
123+
public Builder usingAnyFreePort() {
124+
super.usingAnyFreePort();
125+
return this;
126+
}
127+
128+
/**
129+
* Defines the environment for the launched driver server. These
130+
* settings will be inherited by every browser session launched by the
131+
* server.
132+
*
133+
* @param environment A map of the environment variables to launch the
134+
* server with.
135+
* @return A self reference.
136+
*/
137+
@Beta
138+
public Builder withEnvironment(Map<String, String> environment) {
139+
super.withEnvironment(environment);
140+
return this;
141+
}
142+
143+
/**
144+
* Configures the driver server to write log to the given file.
145+
*
146+
* @param logFile A file to write log to.
147+
* @return A self reference.
148+
*/
149+
public Builder withLogFile(File logFile) {
150+
super.withLogFile(logFile);
151+
return this;
152+
}
153+
93154
/**
94155
* Configures the driver server verbosity.
95156
*

0 commit comments

Comments
 (0)