Skip to content

Commit a667b3b

Browse files
committed
Ensure we set capabilities consistently in *Capabilities
By lifting the logic from `MutableCapabilities` up.
1 parent f288372 commit a667b3b

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

java/client/src/org/openqa/selenium/AbstractCapabilities.java

+29
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
package org.openqa.selenium;
1919

20+
import org.openqa.selenium.logging.LogLevelMapping;
21+
import org.openqa.selenium.logging.LoggingPreferences;
22+
2023
import java.util.Collection;
2124
import java.util.Collections;
2225
import java.util.Comparator;
@@ -44,6 +47,32 @@ protected void setCapability(String key, Object value) {
4447
return;
4548
}
4649

50+
if ("loggingPrefs".equals(key) && value instanceof Map) {
51+
LoggingPreferences prefs = new LoggingPreferences();
52+
@SuppressWarnings("unchecked") Map<String, String> prefsMap = (Map<String, String>) value;
53+
54+
for (String logType : prefsMap.keySet()) {
55+
prefs.enable(logType, LogLevelMapping.toLevel(prefsMap.get(logType)));
56+
}
57+
caps.put(key, prefs);
58+
return;
59+
}
60+
61+
if ("platform".equals(key) && value instanceof String) {
62+
try {
63+
caps.put(key, Platform.fromString((String) value));
64+
} catch (WebDriverException e) {
65+
caps.put(key, value);
66+
}
67+
return;
68+
}
69+
70+
if ("unexpectedAlertBehaviour".equals(key)) {
71+
caps.put("unexpectedAlertBehaviour", value);
72+
caps.put("unhandledPromptBehavior", value);
73+
return;
74+
}
75+
4776
caps.put(key, value);
4877
}
4978

java/client/src/org/openqa/selenium/MutableCapabilities.java

-29
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
package org.openqa.selenium;
1919

2020

21-
import org.openqa.selenium.logging.LogLevelMapping;
22-
import org.openqa.selenium.logging.LoggingPreferences;
23-
2421
import java.io.Serializable;
2522
import java.util.Collections;
2623
import java.util.HashSet;
@@ -101,32 +98,6 @@ public void setCapability(String key, Object value) {
10198
return;
10299
}
103100

104-
if ("loggingPrefs".equals(key) && value instanceof Map) {
105-
LoggingPreferences prefs = new LoggingPreferences();
106-
@SuppressWarnings("unchecked") Map<String, String> prefsMap = (Map<String, String>) value;
107-
108-
for (String logType : prefsMap.keySet()) {
109-
prefs.enable(logType, LogLevelMapping.toLevel(prefsMap.get(logType)));
110-
}
111-
super.setCapability(key, prefs);
112-
return;
113-
}
114-
115-
if ("platform".equals(key) && value instanceof String) {
116-
try {
117-
super.setCapability(key, Platform.fromString((String) value));
118-
} catch (WebDriverException e) {
119-
super.setCapability(key, value);
120-
}
121-
return;
122-
}
123-
124-
if ("unexpectedAlertBehaviour".equals(key)) {
125-
super.setCapability("unexpectedAlertBehaviour", value);
126-
super.setCapability("unhandledPromptBehavior", value);
127-
return;
128-
}
129-
130101
super.setCapability(key, value);
131102
}
132103
}

0 commit comments

Comments
 (0)