@@ -348,120 +348,143 @@ private void addDriverConfigs(
348
348
Multimap <WebDriverInfo , SessionFactory > driverConfigs = HashMultimap .create ();
349
349
350
350
// get all driver configuration settings
351
- config .getAll (NODE_SECTION , "driver-configuration" )
352
- // if settings exist
353
- .ifPresent (drivers -> {
354
- Map <String , String > configMap = new HashMap <>();
355
- List <Map <String , String >> configList = new ArrayList <>();
356
-
357
- // iterate over driver settings
358
- for (String setting : drivers ) {
359
- // split this setting into key/value pair
360
- String [] values = setting .split ("=" , 2 );
361
- // if format is invalid
362
- if (values .length != 2 ) {
363
- throw new ConfigException ("Driver setting '" + setting
364
- + "' does not adhere to the required 'key=value' format!" );
365
- }
366
- // if this is a record separator
367
- if (values [0 ].equals (Config .DELIM_KEY )) {
368
- // if config lacks settings
369
- if (configMap .isEmpty ()) {
370
- throw new ConfigException ("Found config delimiter with no preceding settings!" );
371
- }
372
-
373
- // if config lacks 'display-name' setting
374
- if (!configMap .containsKey ("display-name" )) {
375
- throw new ConfigException ("Found config with no 'display-name' setting! " + configMap );
376
- }
377
-
378
- // if config lacks 'stereotype' setting
379
- if (!configMap .containsKey ("stereotype" )) {
380
- throw new ConfigException ("Found config with no 'stereotype' setting! " + configMap );
381
- }
382
-
383
- // add config to list
384
- configList .add (configMap );
385
- // prepare for next config
386
- configMap = new HashMap <>();
387
- } else {
388
- // add setting to config
389
- configMap .put (values [0 ], unquote (values [1 ]));
390
- }
391
- }
351
+ config
352
+ .getAll (NODE_SECTION , "driver-configuration" )
353
+ // if settings exist
354
+ .ifPresent (
355
+ drivers -> {
356
+ Map <String , String > configMap = new HashMap <>();
357
+ List <Map <String , String >> configList = new ArrayList <>();
358
+
359
+ // iterate over driver settings
360
+ for (String setting : drivers ) {
361
+ // split this setting into key/value pair
362
+ String [] values = setting .split ("=" , 2 );
363
+ // if format is invalid
364
+ if (values .length != 2 ) {
365
+ throw new ConfigException (
366
+ "Driver setting '"
367
+ + setting
368
+ + "' does not adhere to the required 'key=value' format!" );
369
+ }
370
+ // if this is a record separator
371
+ if (values [0 ].equals (Config .DELIM_KEY )) {
372
+ // if config lacks settings
373
+ if (configMap .isEmpty ()) {
374
+ throw new ConfigException ("Found config delimiter with no preceding settings!" );
375
+ }
392
376
393
- // if no configs were found
394
- if (configList .isEmpty ()) {
395
- throw new ConfigException ("No driver configs were found!" );
396
- }
377
+ // if config lacks 'display-name' setting
378
+ if (!configMap .containsKey ("display-name" )) {
379
+ throw new ConfigException (
380
+ "Found config with no 'display-name' setting! " + configMap );
381
+ }
397
382
398
- List <DriverService .Builder <?, ?>> builderList = new ArrayList <>();
399
- ServiceLoader .load (DriverService .Builder .class ).forEach (builderList ::add );
400
-
401
- List <WebDriverInfo > infoList = new ArrayList <>();
402
- ServiceLoader .load (WebDriverInfo .class ).forEach (infoList ::add );
403
-
404
- // iterate over driver configs
405
- configList .forEach (thisConfig -> {
406
- // create Capabilities object from stereotype of this config
407
- Capabilities confStereotype = JSON .toType (thisConfig .get ("stereotype" ), Capabilities .class );
408
-
409
- // extract driver executable path from this config
410
- String webDriverExecutablePath = thisConfig .get ("webdriver-executable" );
411
- // if executable path is specified
412
- if (null != webDriverExecutablePath ) {
413
- // create File object from executable path string
414
- File webDriverExecutable = new File (webDriverExecutablePath );
415
- // if specified path isn't a file
416
- if (!webDriverExecutable .isFile ()) {
417
- LOG .warning ("Driver executable does not seem to be a file! " + webDriverExecutablePath );
418
- }
419
-
420
- // if specified path isn't executable
421
- if (!webDriverExecutable .canExecute ()) {
422
- LOG .warning ("Driver file exists but does not seem to be a executable! " + webDriverExecutablePath );
423
- }
424
-
425
- // add specified driver executable path to capabilities
426
- confStereotype = new PersistentCapabilities (confStereotype )
427
- .setCapability ("se:webDriverExecutable" , webDriverExecutablePath );
428
- }
429
-
430
- Capabilities stereotype = enhanceStereotype (confStereotype );
431
- String configName = thisConfig .getOrDefault ("display-name" , "Custom Slot Config" );
432
-
433
- WebDriverInfo info = infoList .stream ()
434
- .filter (webDriverInfo -> webDriverInfo .isSupporting (stereotype ))
435
- .findFirst ()
436
- .orElseThrow (() ->
437
- new ConfigException ("Unable to find matching driver for %s" , stereotype ));
438
-
439
- int driverMaxSessions = Integer .parseInt (thisConfig .getOrDefault (
440
- "max-sessions" , String .valueOf (info .getMaximumSimultaneousSessions ())));
441
- Require .positive ("Driver max sessions" , driverMaxSessions );
442
-
443
- WebDriverInfo driverInfoConfig = createConfiguredDriverInfo (info , stereotype , configName );
444
-
445
- builderList .stream ()
446
- .filter (builder -> builder .score (stereotype ) > 0 )
447
- .max (Comparator .comparingInt (builder -> builder .score (stereotype )))
448
- .ifPresent (builder -> {
449
- ImmutableCapabilities immutable = new ImmutableCapabilities (stereotype );
450
- int maxDriverSessions = getDriverMaxSessions (info , driverMaxSessions );
451
- for (int i = 0 ; i < maxDriverSessions ; i ++) {
452
- driverConfigs .putAll (driverInfoConfig , factoryFactory .apply (immutable ));
383
+ // if config lacks 'stereotype' setting
384
+ if (!configMap .containsKey ("stereotype" )) {
385
+ throw new ConfigException (
386
+ "Found config with no 'stereotype' setting! " + configMap );
387
+ }
388
+
389
+ // add config to list
390
+ configList .add (configMap );
391
+ // prepare for next config
392
+ configMap = new HashMap <>();
393
+ } else {
394
+ // add setting to config
395
+ configMap .put (values [0 ], unquote (values [1 ]));
453
396
}
454
397
}
455
- );
456
- }
457
- );
458
- }
459
- );
398
+
399
+ // if no configs were found
400
+ if (configList .isEmpty ()) {
401
+ throw new ConfigException ("No driver configs were found!" );
402
+ }
403
+
404
+ List <DriverService .Builder <?, ?>> builderList = new ArrayList <>();
405
+ ServiceLoader .load (DriverService .Builder .class ).forEach (builderList ::add );
406
+
407
+ List <WebDriverInfo > infoList = new ArrayList <>();
408
+ ServiceLoader .load (WebDriverInfo .class ).forEach (infoList ::add );
409
+
410
+ // iterate over driver configs
411
+ configList .forEach (
412
+ thisConfig -> {
413
+ // create Capabilities object from stereotype of this config
414
+ Capabilities confStereotype =
415
+ JSON .toType (thisConfig .get ("stereotype" ), Capabilities .class );
416
+
417
+ // extract driver executable path from this config
418
+ String webDriverExecutablePath = thisConfig .get ("webdriver-executable" );
419
+ // if executable path is specified
420
+ if (null != webDriverExecutablePath ) {
421
+ // create File object from executable path string
422
+ File webDriverExecutable = new File (webDriverExecutablePath );
423
+ // if specified path isn't a file
424
+ if (!webDriverExecutable .isFile ()) {
425
+ LOG .warning (
426
+ "Driver executable does not seem to be a file! "
427
+ + webDriverExecutablePath );
428
+ }
429
+
430
+ // if specified path isn't executable
431
+ if (!webDriverExecutable .canExecute ()) {
432
+ LOG .warning (
433
+ "Driver file exists but does not seem to be a executable! "
434
+ + webDriverExecutablePath );
435
+ }
436
+
437
+ // add specified driver executable path to capabilities
438
+ confStereotype =
439
+ new PersistentCapabilities (confStereotype )
440
+ .setCapability ("se:webDriverExecutable" , webDriverExecutablePath );
441
+ }
442
+
443
+ Capabilities stereotype = enhanceStereotype (confStereotype );
444
+ String configName =
445
+ thisConfig .getOrDefault ("display-name" , "Custom Slot Config" );
446
+
447
+ WebDriverInfo info =
448
+ infoList .stream ()
449
+ .filter (webDriverInfo -> webDriverInfo .isSupporting (stereotype ))
450
+ .findFirst ()
451
+ .orElseThrow (
452
+ () ->
453
+ new ConfigException (
454
+ "Unable to find matching driver for %s" , stereotype ));
455
+
456
+ int driverMaxSessions =
457
+ Integer .parseInt (
458
+ thisConfig .getOrDefault (
459
+ "max-sessions" ,
460
+ String .valueOf (info .getMaximumSimultaneousSessions ())));
461
+ Require .positive ("Driver max sessions" , driverMaxSessions );
462
+
463
+ WebDriverInfo driverInfoConfig =
464
+ createConfiguredDriverInfo (info , stereotype , configName );
465
+
466
+ builderList .stream ()
467
+ .filter (builder -> builder .score (stereotype ) > 0 )
468
+ .max (Comparator .comparingInt (builder -> builder .score (stereotype )))
469
+ .ifPresent (
470
+ builder -> {
471
+ ImmutableCapabilities immutable =
472
+ new ImmutableCapabilities (stereotype );
473
+ int maxDriverSessions = getDriverMaxSessions (info , driverMaxSessions );
474
+ for (int i = 0 ; i < maxDriverSessions ; i ++) {
475
+ driverConfigs .putAll (
476
+ driverInfoConfig , factoryFactory .apply (immutable ));
477
+ }
478
+ });
479
+ });
480
+ });
460
481
461
482
driverConfigs .asMap ().entrySet ().stream ()
462
- .peek (this ::report )
463
- .forEach (entry ->
464
- sessionFactories .putAll (entry .getKey ().getCanonicalCapabilities (), entry .getValue ()));
483
+ .peek (this ::report )
484
+ .forEach (
485
+ entry ->
486
+ sessionFactories .putAll (
487
+ entry .getKey ().getCanonicalCapabilities (), entry .getValue ()));
465
488
}
466
489
467
490
private void addDetectedDrivers (
0 commit comments