88import org .apache .commons .lang3 .StringUtils ;
99import org .openqa .selenium .MutableCapabilities ;
1010import org .openqa .selenium .PageLoadStrategy ;
11+ import org .openqa .selenium .logging .LoggingPreferences ;
12+
1113import java .io .File ;
1214import java .io .IOException ;
1315import java .util .Arrays ;
1416import java .util .Collections ;
1517import java .util .List ;
1618import java .util .Map ;
19+ import java .util .logging .Level ;
1720import java .util .stream .Collectors ;
1821
1922abstract class DriverSettings implements IDriverSettings {
2023
2124 private final ISettingsFile settingsFile ;
2225 private Map <String , Object > options ;
2326 private Map <String , Object > capabilities ;
27+ private Map <String , Level > loggingPreferences ;
2428 private List <String > startArguments ;
2529
2630 protected DriverSettings (ISettingsFile settingsFile ) {
@@ -45,6 +49,15 @@ protected Map<String, Object> getBrowserCapabilities() {
4549 return capabilities ;
4650 }
4751
52+ protected Map <String , Level > getLoggingPreferences () {
53+ if (loggingPreferences == null ) {
54+ loggingPreferences = getMapOrEmpty (CapabilityType .LOGGING_PREFERENCES ).entrySet ().stream ().collect (
55+ Collectors .toMap (entry -> entry .getKey ().toLowerCase (),
56+ pair -> Level .parse (pair .getValue ().toString ().toUpperCase ())));
57+ }
58+ return loggingPreferences ;
59+ }
60+
4861 private Map <String , Object > getMapOrEmpty (CapabilityType capabilityType ) {
4962 String path = getDriverSettingsPath (capabilityType );
5063 Map <String , Object > map = getSettingsFile ().isValuePresent (path ) ? getSettingsFile ().getMap (path ) : Collections .emptyMap ();
@@ -123,6 +136,14 @@ void setCapabilities(MutableCapabilities options) {
123136 getBrowserCapabilities ().forEach (options ::setCapability );
124137 }
125138
139+ void setLoggingPreferences (MutableCapabilities options , String capabilityKey ) {
140+ if (!getLoggingPreferences ().isEmpty ()) {
141+ LoggingPreferences logs = new LoggingPreferences ();
142+ getLoggingPreferences ().forEach (logs ::enable );
143+ options .setCapability (capabilityKey , logs );
144+ }
145+ }
146+
126147 @ Override
127148 public String getDownloadDir () {
128149 Map <String , Object > browserOptions = getBrowserOptions ();
@@ -136,7 +157,10 @@ public String getDownloadDir() {
136157 }
137158
138159 private enum CapabilityType {
139- CAPABILITIES ("capabilities" ), OPTIONS ("options" ), START_ARGS ("startArguments" );
160+ CAPABILITIES ("capabilities" ),
161+ OPTIONS ("options" ),
162+ START_ARGS ("startArguments" ),
163+ LOGGING_PREFERENCES ("loggingPreferences" );
140164
141165 private final String key ;
142166
0 commit comments