@@ -123,58 +123,51 @@ public static final class SystemProperty {
123123 protected FirefoxBinary binary ;
124124
125125 public FirefoxDriver () {
126- this (null , null , null , null );
127- }
128-
129- public FirefoxDriver (FirefoxBinary binary ) {
130- this (binary , null , null , null );
126+ this (new FirefoxBinary (), null );
131127 }
132128
133129 public FirefoxDriver (FirefoxProfile profile ) {
134- this (null , profile , null , null );
130+ this (new FirefoxBinary (), profile );
135131 }
136132
137133 public FirefoxDriver (Capabilities desiredCapabilities ) {
138- this (null , null , desiredCapabilities , null );
134+ this (getBinary (desiredCapabilities ), extractProfile (desiredCapabilities , null ),
135+ desiredCapabilities );
139136 }
140137
141138 public FirefoxDriver (Capabilities desiredCapabilities , Capabilities requiredCapabilities ) {
142- this (null , null , desiredCapabilities , requiredCapabilities );
143- }
144-
145- public FirefoxDriver (FirefoxBinary binary , FirefoxProfile profile ) {
146- this (binary , profile , null , null );
139+ this (getBinary (desiredCapabilities ), extractProfile (desiredCapabilities , requiredCapabilities ),
140+ desiredCapabilities , requiredCapabilities );
147141 }
148142
149- public FirefoxDriver (FirefoxBinary binary , FirefoxProfile profile , Capabilities capabilities ) {
150- this (binary , profile , capabilities , null );
151- }
152-
153- public FirefoxDriver (FirefoxBinary binary , FirefoxProfile profile ,
154- Capabilities desiredCapabilities , Capabilities requiredCapabilities ) {
155- this (createCommandExecutor (desiredCapabilities , requiredCapabilities , binary , profile ),
156- populateProfile (profile , desiredCapabilities ), requiredCapabilities );
157- this .binary = binary ;
158- }
159-
160- public FirefoxDriver (GeckoDriverService driverService ) {
161- this (new DriverCommandExecutor (driverService ), null , null );
162- }
143+ private static FirefoxProfile extractProfile (Capabilities desiredCapabilities ,
144+ Capabilities requiredCapabilities ) {
163145
164- public FirefoxDriver (GeckoDriverService driverService , Capabilities desiredCapabilities ) {
165- this (new DriverCommandExecutor (driverService ), desiredCapabilities , null );
166- }
146+ FirefoxProfile profile = null ;
147+ Object raw = null ;
148+ if (desiredCapabilities != null && desiredCapabilities .getCapability (PROFILE ) != null ) {
149+ raw = desiredCapabilities .getCapability (PROFILE );
150+ }
151+ if (requiredCapabilities != null && requiredCapabilities .getCapability (PROFILE ) != null ) {
152+ raw = requiredCapabilities .getCapability (PROFILE );
153+ }
154+ if (raw != null ) {
155+ if (raw instanceof FirefoxProfile ) {
156+ profile = (FirefoxProfile ) raw ;
157+ } else if (raw instanceof String ) {
158+ try {
159+ profile = FirefoxProfile .fromJson ((String ) raw );
160+ } catch (IOException e ) {
161+ throw new WebDriverException (e );
162+ }
163+ }
164+ }
165+ profile = getProfile (profile );
167166
168- public FirefoxDriver (GeckoDriverService driverService , Capabilities desiredCapabilities ,
169- Capabilities requiredCapabilities ) {
170- this (new DriverCommandExecutor (driverService ), desiredCapabilities , requiredCapabilities );
171- }
167+ populateProfile (profile , desiredCapabilities );
168+ populateProfile (profile , requiredCapabilities );
172169
173- private FirefoxDriver (CommandExecutor executor , Capabilities desiredCapabilities ,
174- Capabilities requiredCapabilities ) {
175- super (executor ,
176- dropCapabilities (desiredCapabilities ),
177- dropCapabilities (requiredCapabilities ));
170+ return profile ;
178171 }
179172
180173 static Capabilities populateProfile (FirefoxProfile profile , Capabilities capabilities ) {
@@ -198,58 +191,34 @@ static Capabilities populateProfile(FirefoxProfile profile, Capabilities capabil
198191 }
199192 }
200193
201- DesiredCapabilities toReturn = capabilities instanceof DesiredCapabilities ?
202- (DesiredCapabilities ) capabilities :
203- new DesiredCapabilities (capabilities );
204-
205- if (! isLegacy (capabilities )) {
206- Object rawOptions = capabilities .getCapability (FIREFOX_OPTIONS );
207- if (rawOptions instanceof Map ) {
208- try {
209- @ SuppressWarnings ("unchecked" )
210- Map <String , Object > map = (Map <String , Object >) rawOptions ;
211- rawOptions = FirefoxOptions .fromJsonMap (map );
212- } catch (IOException e ) {
213- throw new WebDriverException (e );
214- }
215- }
216- if (rawOptions == null ) {
217- rawOptions = capabilities .getCapability (OLD_FIREFOX_OPTIONS );
218- }
219- if (rawOptions != null && !(rawOptions instanceof FirefoxOptions )) {
220- throw new WebDriverException ("Firefox option was set, but is not a FirefoxOption: " + rawOptions );
221- }
222- FirefoxOptions options = (FirefoxOptions ) rawOptions ;
223- if (options == null ) {
224- options = new FirefoxOptions ();
194+ Object rawOptions = capabilities .getCapability (FIREFOX_OPTIONS );
195+ if (rawOptions instanceof Map ) {
196+ try {
197+ @ SuppressWarnings ("unchecked" )
198+ Map <String , Object > map = (Map <String , Object >) rawOptions ;
199+ rawOptions = FirefoxOptions .fromJsonMap (map );
200+ } catch (IOException e ) {
201+ throw new WebDriverException (e );
225202 }
226- options .setProfileSafely (profile );
227-
228- toReturn .setCapability (OLD_FIREFOX_OPTIONS , options );
229- toReturn .setCapability (FIREFOX_OPTIONS , options );
230203 }
231-
232- return toReturn ;
233- }
234-
235- private static final CommandExecutor createCommandExecutor (Capabilities desiredCapabilities ,
236- Capabilities requiredCapabilities ,
237- FirefoxBinary binary ,
238- FirefoxProfile profile ) {
239- if (isLegacy (desiredCapabilities )) {
240- if (binary == null ) {
241- binary = getBinary (desiredCapabilities );
242- }
243- if (profile == null ) {
244- profile = extractProfile (desiredCapabilities , requiredCapabilities );
245- }
246- return new LazyCommandExecutor (binary , profile );
204+ if (rawOptions == null ) {
205+ rawOptions = capabilities .getCapability (OLD_FIREFOX_OPTIONS );
247206 }
248- GeckoDriverService .Builder builder = new GeckoDriverService .Builder ().usingPort (0 );
249- if (binary != null ) {
250- builder .usingFirefoxBinary (binary );
207+ if (rawOptions != null && !(rawOptions instanceof FirefoxOptions )) {
208+ throw new WebDriverException ("Firefox option was set, but is not a FirefoxOption: " + rawOptions );
251209 }
252- return new DriverCommandExecutor (builder .build ());
210+ FirefoxOptions options = (FirefoxOptions ) rawOptions ;
211+ if (options == null ) {
212+ options = new FirefoxOptions ();
213+ }
214+ options .setProfileSafely (profile );
215+
216+ DesiredCapabilities toReturn = capabilities instanceof DesiredCapabilities ?
217+ (DesiredCapabilities ) capabilities :
218+ new DesiredCapabilities (capabilities );
219+ toReturn .setCapability (OLD_FIREFOX_OPTIONS , options );
220+ toReturn .setCapability (FIREFOX_OPTIONS , options );
221+ return toReturn ;
253222 }
254223
255224 private static FirefoxBinary getBinary (Capabilities capabilities ) {
@@ -270,7 +239,7 @@ private static FirefoxBinary getBinary(Capabilities capabilities) {
270239 if (capabilities .getCapability (VERSION ) != null ) {
271240 try {
272241 FirefoxBinary .Channel channel = FirefoxBinary .Channel .fromString (
273- (String ) capabilities .getCapability (VERSION ));
242+ (String ) capabilities .getCapability (VERSION ));
274243 return new FirefoxBinary (channel );
275244 } catch (WebDriverException ex ) {
276245 return new FirefoxBinary ((String ) capabilities .getCapability (VERSION ));
@@ -280,34 +249,52 @@ private static FirefoxBinary getBinary(Capabilities capabilities) {
280249 return new FirefoxBinary ();
281250 }
282251
283- private static FirefoxProfile extractProfile (Capabilities desiredCapabilities ,
284- Capabilities requiredCapabilities ) {
252+ public FirefoxDriver (FirefoxBinary binary , FirefoxProfile profile ) {
253+ this (binary , profile , populateProfile (profile , DesiredCapabilities .firefox ()));
254+ }
285255
286- FirefoxProfile profile = null ;
287- Object raw = null ;
288- if (desiredCapabilities != null && desiredCapabilities .getCapability (PROFILE ) != null ) {
289- raw = desiredCapabilities .getCapability (PROFILE );
290- }
291- if (requiredCapabilities != null && requiredCapabilities .getCapability (PROFILE ) != null ) {
292- raw = requiredCapabilities .getCapability (PROFILE );
293- }
294- if (raw != null ) {
295- if (raw instanceof FirefoxProfile ) {
296- profile = (FirefoxProfile ) raw ;
297- } else if (raw instanceof String ) {
298- try {
299- profile = FirefoxProfile .fromJson ((String ) raw );
300- } catch (IOException e ) {
301- throw new WebDriverException (e );
302- }
303- }
304- }
305- profile = getProfile (profile );
256+ public FirefoxDriver (FirefoxBinary binary , FirefoxProfile profile , Capabilities capabilities ) {
257+ this (binary , profile , populateProfile (profile , capabilities ), null );
258+ }
306259
307- populateProfile (profile , desiredCapabilities );
308- populateProfile (profile , requiredCapabilities );
260+ public FirefoxDriver (FirefoxBinary binary , FirefoxProfile profile ,
261+ Capabilities desiredCapabilities , Capabilities requiredCapabilities ) {
262+ this (createCommandExecutor (populateProfile (profile , desiredCapabilities ), binary , profile ),
263+ populateProfile (profile , desiredCapabilities ), requiredCapabilities );
264+ this .binary = binary ;
265+ }
309266
310- return profile ;
267+ public FirefoxDriver (GeckoDriverService driverService ) {
268+ this (new DriverCommandExecutor (driverService ), null , null );
269+ }
270+
271+ public FirefoxDriver (GeckoDriverService driverService , Capabilities desiredCapabilities ) {
272+ this (new DriverCommandExecutor (driverService ), desiredCapabilities , null );
273+ }
274+
275+ public FirefoxDriver (GeckoDriverService driverService , Capabilities desiredCapabilities ,
276+ Capabilities requiredCapabilities ) {
277+ this (new DriverCommandExecutor (driverService ), desiredCapabilities , requiredCapabilities );
278+ }
279+
280+ private FirefoxDriver (CommandExecutor executor , Capabilities desiredCapabilities ,
281+ Capabilities requiredCapabilities ) {
282+ super (executor ,
283+ dropCapabilities (desiredCapabilities ),
284+ dropCapabilities (requiredCapabilities ));
285+ }
286+
287+ private static final CommandExecutor createCommandExecutor (Capabilities desiredCapabilities ,
288+ FirefoxBinary binary ,
289+ FirefoxProfile profile ) {
290+ if (isLegacy (desiredCapabilities )) {
291+ return new LazyCommandExecutor (binary , profile );
292+ }
293+ GeckoDriverService .Builder builder = new GeckoDriverService .Builder ().usingPort (0 );
294+ if (binary != null ) {
295+ builder .usingFirefoxBinary (binary );
296+ }
297+ return new DriverCommandExecutor (builder .build ());
311298 }
312299
313300 @ Override
@@ -354,9 +341,6 @@ private static boolean isLegacy(Capabilities desiredCapabilities) {
354341 if (forceMarionette != null ) {
355342 return !forceMarionette ;
356343 }
357- if (desiredCapabilities == null ) {
358- return false ;
359- }
360344 Object marionette = desiredCapabilities .getCapability (MARIONETTE );
361345 return marionette instanceof Boolean && ! (Boolean ) marionette ;
362346 }
@@ -384,6 +368,7 @@ protected void startClient(Capabilities desiredCapabilities, Capabilities requir
384368 } catch (IOException e ) {
385369 throw new WebDriverException ("An error occurred while connecting to Firefox" , e );
386370 }
371+
387372 }
388373 }
389374
0 commit comments