Skip to content

Commit 3f5ee5c

Browse files
committed
Using a DesiredCapabilities to control WDBS won't always work since the
user may not have access to the capabilities (or the driver won't implement HasCapabilities). Add a method to WebDriverCommandProcessor to control whether to emulate Selenium's alert API.
1 parent 6cbde7e commit 3f5ee5c

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

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

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.openqa.selenium;
1818

1919
import com.google.common.annotations.VisibleForTesting;
20-
import com.google.common.base.Optional;
2120
import com.google.common.base.Supplier;
2221
import com.google.common.collect.Maps;
2322

@@ -35,17 +34,11 @@
3534
*/
3635
public class WebDriverCommandProcessor implements CommandProcessor, WrapsDriver {
3736

38-
/**
39-
* Capability key that dictates whether to emulate Selenium's alert handling and override
40-
* the native alert functions. Defaults to true.
41-
*/
42-
public static final String ENABLE_ALERT_OVERRIDES_CAPABILITY =
43-
"selenium.emulation.overrideAlerts";
44-
4537
private final Map<String, SeleneseCommand<?>> seleneseMethods = Maps.newHashMap();
4638
private final String baseUrl;
4739
private final Timer timer;
4840
private final CompoundMutator scriptMutator;
41+
private boolean enableAlertOverrides = true;
4942
private Supplier<WebDriver> maker;
5043
private WebDriver driver;
5144

@@ -179,22 +172,21 @@ protected void assertDriverSupportsJavascript(WebDriver driver) {
179172
}
180173
}
181174

182-
private boolean enableOverrides() {
183-
Optional<Boolean> enableOverrides = Optional.absent();
184-
if (driver instanceof HasCapabilities) {
185-
Object tmp = ((HasCapabilities) driver).getCapabilities().getCapability(
186-
ENABLE_ALERT_OVERRIDES_CAPABILITY);
187-
enableOverrides = Optional.fromNullable((Boolean) tmp);
188-
}
189-
return enableOverrides.or(true); // Default to true if capability wasn't specified.
175+
/**
176+
* Sets whether to enable emulation of Selenium's alert handling functions or
177+
* to preserve WebDriver's alert handling. This has no affect after calling
178+
* {@link #start()}.
179+
*/
180+
public void setEnableAlertOverrides(boolean enableAlertOverrides) {
181+
this.enableAlertOverrides = enableAlertOverrides;
190182
}
191183

192184
private void setUpMethodMap() {
193185
JavascriptLibrary javascriptLibrary = new JavascriptLibrary();
194186
ElementFinder elementFinder = new ElementFinder(javascriptLibrary);
195187
KeyState keyState = new KeyState();
196188

197-
AlertOverride alertOverride = new AlertOverride(enableOverrides());
189+
AlertOverride alertOverride = new AlertOverride(enableAlertOverrides);
198190
Windows windows = new Windows(driver);
199191

200192
// Note the we use the names used by the CommandProcessor

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy