77import org .apache .commons .lang3 .StringUtils ;
88import org .openqa .selenium .MutableCapabilities ;
99import org .openqa .selenium .PageLoadStrategy ;
10+ import org .openqa .selenium .chromium .ChromiumOptions ;
1011import org .openqa .selenium .logging .LoggingPreferences ;
1112
1213import java .io .File ;
@@ -25,6 +26,7 @@ abstract class DriverSettings implements IDriverSettings {
2526 private Map <String , Object > capabilities ;
2627 private Map <String , Level > loggingPreferences ;
2728 private List <String > startArguments ;
29+ private List <String > excludedArguments ;
2830
2931 protected DriverSettings (ISettingsFile settingsFile ) {
3032 this .settingsFile = settingsFile ;
@@ -81,6 +83,23 @@ protected List<String> getBrowserStartArguments() {
8183 return startArguments ;
8284 }
8385
86+ protected List <String > getExcludedArguments () {
87+ if (excludedArguments == null ) {
88+ String path = getDriverSettingsPath (CapabilityType .EXCLUDED_ARGS );
89+ boolean isValuePresent ;
90+ try {
91+ getSettingsFile ().getValue (path );
92+ isValuePresent = true ;
93+ }
94+ catch (IllegalArgumentException e ) {
95+ isValuePresent = false ;
96+ }
97+ excludedArguments = isValuePresent ? getSettingsFile ().getList (path ) : Collections .emptyList ();
98+ logCollection ("loc.browser.excludedArguments" , excludedArguments );
99+ }
100+ return excludedArguments ;
101+ }
102+
84103 protected String getBinaryLocation (String defaultBinaryLocation ) {
85104 String value = (String ) getSettingsFile ().getValueOrDefault (getDriverSettingsPath ("binaryLocation" ), defaultBinaryLocation );
86105 int varStartIndex = value .indexOf ('%' );
@@ -91,7 +110,7 @@ protected String getBinaryLocation(String defaultBinaryLocation) {
91110 }
92111
93112 @ SafeVarargs
94- private final <T > void logCollection (String messageKey , final T ... elements ) {
113+ private <T > void logCollection (String messageKey , final T ... elements ) {
95114 if (elements .length == 1 &&
96115 ((elements [0 ] instanceof Map && !((Map )elements [0 ]).isEmpty ())
97116 || (elements [0 ] instanceof List && !((List )elements [0 ]).isEmpty ()))) {
@@ -119,6 +138,10 @@ void setCapabilities(MutableCapabilities options) {
119138 getBrowserCapabilities ().forEach (options ::setCapability );
120139 }
121140
141+ <T extends ChromiumOptions <T >> void setExcludedArguments (T chromiumOptions ) {
142+ chromiumOptions .setExperimentalOption ("excludeSwitches" , getExcludedArguments ());
143+ }
144+
122145 void setLoggingPreferences (MutableCapabilities options , String capabilityKey ) {
123146 if (!getLoggingPreferences ().isEmpty ()) {
124147 LoggingPreferences logs = new LoggingPreferences ();
@@ -143,6 +166,7 @@ private enum CapabilityType {
143166 CAPABILITIES ("capabilities" ),
144167 OPTIONS ("options" ),
145168 START_ARGS ("startArguments" ),
169+ EXCLUDED_ARGS ("excludedArguments" ),
146170 LOGGING_PREFERENCES ("loggingPreferences" );
147171
148172 private final String key ;
0 commit comments