17
17
18
18
package org .openqa .selenium .ie ;
19
19
20
- import static com .google .common .base .Preconditions .checkArgument ;
21
- import static com .google .common .base .Preconditions .checkNotNull ;
22
-
23
20
import com .google .common .collect .ImmutableList ;
24
21
import com .google .common .collect .ImmutableMap ;
25
22
26
- import org .openqa .selenium .Beta ;
27
23
import org .openqa .selenium .WebDriverException ;
28
- import org .openqa .selenium .net .PortProber ;
29
24
import org .openqa .selenium .remote .service .DriverService ;
30
25
31
26
import java .io .File ;
32
27
import java .io .IOException ;
33
- import java .util .Map ;
34
28
35
29
/**
36
30
* Manages the life and death of an IEDriverServer.
@@ -102,12 +96,8 @@ public static InternetExplorerDriverService createDefaultService() {
102
96
/**
103
97
* Builder used to configure new {@link InternetExplorerDriverService} instances.
104
98
*/
105
- public static class Builder {
99
+ public static class Builder extends DriverService . Builder < InternetExplorerDriverService > {
106
100
107
- private int port = 0 ;
108
- private File exe = null ;
109
- private ImmutableMap <String , String > environment = ImmutableMap .of ();
110
- private File logFile ;
111
101
private InternetExplorerDriverLogLevel logLevel ;
112
102
private InternetExplorerDriverEngine engineImplementation ;
113
103
private String host = null ;
@@ -116,68 +106,6 @@ public static class Builder {
116
106
private Boolean forceCreateProcess = null ;
117
107
private String ieSwitches = null ;
118
108
119
- /**
120
- * Sets which driver executable the builder will use.
121
- *
122
- * @param file The executable to use.
123
- * @return A self reference.
124
- */
125
- public Builder usingDriverExecutable (File file ) {
126
- checkNotNull (file );
127
- checkExecutable (file );
128
- this .exe = file ;
129
- return this ;
130
- }
131
-
132
- /**
133
- * Sets which port the driver server should be started on. A value of 0 indicates that any
134
- * free port may be used.
135
- *
136
- * @param port The port to use; must be non-negative.
137
- * @return A self reference.
138
- */
139
- public Builder usingPort (int port ) {
140
- checkArgument (port >= 0 , "Invalid port number: %d" , port );
141
- this .port = port ;
142
- return this ;
143
- }
144
-
145
- /**
146
- * Configures the driver server to start on any available port.
147
- *
148
- * @return A self reference.
149
- */
150
- public Builder usingAnyFreePort () {
151
- this .port = 0 ;
152
- return this ;
153
- }
154
-
155
- /**
156
- * Defines the environment for the launched driver server. These
157
- * settings will be inherited by every browser session launched by the
158
- * server.
159
- *
160
- * @param environment A map of the environment variables to launch the
161
- * server with.
162
- * @return A self reference.
163
- */
164
- @ Beta
165
- public Builder withEnvironment (Map <String , String > environment ) {
166
- this .environment = ImmutableMap .copyOf (environment );
167
- return this ;
168
- }
169
-
170
- /**
171
- * Configures the driver server to write log to the given file.
172
- *
173
- * @param logFile A file to write log to.
174
- * @return A self reference.
175
- */
176
- public Builder withLogFile (File logFile ) {
177
- this .logFile = logFile ;
178
- return this ;
179
- }
180
-
181
109
/**
182
110
* Configures the logging level for the driver server.
183
111
*
@@ -233,25 +161,19 @@ public Builder withSilent(Boolean silent) {
233
161
return this ;
234
162
}
235
163
236
- /**
237
- * Creates a new service to manage the driver server. Before creating a new service, the
238
- * builder will find a port for the server to listen to.
239
- *
240
- * @return The new service object.
241
- */
242
- public InternetExplorerDriverService build () {
243
- if (port == 0 ) {
244
- port = PortProber .findFreePort ();
245
- }
246
- if (exe == null ) {
247
- exe = findExecutable ("IEDriverServer" , IE_DRIVER_EXE_PROPERTY ,
248
- "http://code.google.com/p/selenium/wiki/InternetExplorerDriver" ,
249
- "http://selenium-release.storage.googleapis.com/index.html" );
250
- }
251
- if (logFile == null ) {
164
+ @ Override
165
+ protected File findDefaultExecutable () {
166
+ return findExecutable ("IEDriverServer" , IE_DRIVER_EXE_PROPERTY ,
167
+ "http://code.google.com/p/selenium/wiki/InternetExplorerDriver" ,
168
+ "http://selenium-release.storage.googleapis.com/index.html" );
169
+ }
170
+
171
+ @ Override
172
+ protected ImmutableList <String > createArgs () {
173
+ if (getLogFile () == null ) {
252
174
String logFilePath = System .getProperty (IE_DRIVER_LOGFILE_PROPERTY );
253
175
if (logFilePath != null ) {
254
- logFile = new File (logFilePath );
176
+ withLogFile ( new File (logFilePath ) );
255
177
}
256
178
}
257
179
if (logLevel == null ) {
@@ -285,30 +207,36 @@ public InternetExplorerDriverService build() {
285
207
}
286
208
}
287
209
288
- try {
289
- ImmutableList .Builder <String > argsBuilder = ImmutableList .builder ();
290
- argsBuilder .add (String .format ("--port=%d" , port ));
291
- if (logFile != null ) {
292
- argsBuilder .add (String .format ("--log-file=\" %s\" " , logFile .getAbsolutePath ()));
293
- }
294
- if (logLevel != null ) {
295
- argsBuilder .add (String .format ("--log-level=%s" , logLevel .toString ()));
296
- }
297
- if (engineImplementation != null ) {
298
- argsBuilder .add (String .format ("--implementation=%s" , engineImplementation .toString ()));
299
- }
300
- if (host != null ) {
301
- argsBuilder .add (String .format ("--host=%s" , host ));
302
- }
303
- if (extractPath != null ) {
304
- argsBuilder .add (String .format ("--extract-path=\" %s\" " , extractPath .getAbsolutePath ()));
305
- }
306
- if (silent != null && silent .equals (Boolean .TRUE )) {
307
- argsBuilder .add ("--silent" );
308
- }
210
+ ImmutableList .Builder <String > argsBuilder = ImmutableList .builder ();
211
+ argsBuilder .add (String .format ("--port=%d" , getPort ()));
212
+ if (getLogFile () != null ) {
213
+ argsBuilder .add (String .format ("--log-file=\" %s\" " , getLogFile ().getAbsolutePath ()));
214
+ }
215
+ if (logLevel != null ) {
216
+ argsBuilder .add (String .format ("--log-level=%s" , logLevel .toString ()));
217
+ }
218
+ if (engineImplementation != null ) {
219
+ argsBuilder .add (String .format ("--implementation=%s" , engineImplementation .toString ()));
220
+ }
221
+ if (host != null ) {
222
+ argsBuilder .add (String .format ("--host=%s" , host ));
223
+ }
224
+ if (extractPath != null ) {
225
+ argsBuilder .add (String .format ("--extract-path=\" %s\" " , extractPath .getAbsolutePath ()));
226
+ }
227
+ if (silent != null && silent .equals (Boolean .TRUE )) {
228
+ argsBuilder .add ("--silent" );
229
+ }
309
230
310
- return new InternetExplorerDriverService (exe , port , argsBuilder .build (), environment );
231
+ return argsBuilder .build ();
232
+ }
311
233
234
+ @ Override
235
+ protected InternetExplorerDriverService createDriverService (File exe , int port ,
236
+ ImmutableList <String > args ,
237
+ ImmutableMap <String , String > environment ) {
238
+ try {
239
+ return new InternetExplorerDriverService (exe , port , args , environment );
312
240
} catch (IOException e ) {
313
241
throw new WebDriverException (e );
314
242
}
0 commit comments