8
8
import org .apache .commons .lang3 .StringUtils ;
9
9
import org .openqa .selenium .MutableCapabilities ;
10
10
import org .openqa .selenium .PageLoadStrategy ;
11
+ import org .openqa .selenium .logging .LoggingPreferences ;
12
+
11
13
import java .io .File ;
12
14
import java .io .IOException ;
13
15
import java .util .Arrays ;
14
16
import java .util .Collections ;
15
17
import java .util .List ;
16
18
import java .util .Map ;
19
+ import java .util .logging .Level ;
17
20
import java .util .stream .Collectors ;
18
21
19
22
abstract class DriverSettings implements IDriverSettings {
20
23
21
24
private final ISettingsFile settingsFile ;
22
25
private Map <String , Object > options ;
23
26
private Map <String , Object > capabilities ;
27
+ private Map <String , Level > loggingPreferences ;
24
28
private List <String > startArguments ;
25
29
26
30
protected DriverSettings (ISettingsFile settingsFile ) {
@@ -45,6 +49,15 @@ protected Map<String, Object> getBrowserCapabilities() {
45
49
return capabilities ;
46
50
}
47
51
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
+
48
61
private Map <String , Object > getMapOrEmpty (CapabilityType capabilityType ) {
49
62
String path = getDriverSettingsPath (capabilityType );
50
63
Map <String , Object > map = getSettingsFile ().isValuePresent (path ) ? getSettingsFile ().getMap (path ) : Collections .emptyMap ();
@@ -123,6 +136,14 @@ void setCapabilities(MutableCapabilities options) {
123
136
getBrowserCapabilities ().forEach (options ::setCapability );
124
137
}
125
138
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
+
126
147
@ Override
127
148
public String getDownloadDir () {
128
149
Map <String , Object > browserOptions = getBrowserOptions ();
@@ -136,7 +157,10 @@ public String getDownloadDir() {
136
157
}
137
158
138
159
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" );
140
164
141
165
private final String key ;
142
166
0 commit comments