Skip to content

Commit 2f39421

Browse files
committed
[java] implement custom method to toggle downloads enabled
1 parent b2f05ef commit 2f39421

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

java/src/org/openqa/selenium/remote/AbstractDriverOptions.java

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import static org.openqa.selenium.remote.CapabilityType.ACCEPT_INSECURE_CERTS;
2121
import static org.openqa.selenium.remote.CapabilityType.BROWSER_VERSION;
22+
import static org.openqa.selenium.remote.CapabilityType.ENABLE_DOWNLOADS;
2223
import static org.openqa.selenium.remote.CapabilityType.PAGE_LOAD_STRATEGY;
2324
import static org.openqa.selenium.remote.CapabilityType.PLATFORM_NAME;
2425
import static org.openqa.selenium.remote.CapabilityType.PROXY;
@@ -101,6 +102,11 @@ public DO setProxy(Proxy proxy) {
101102
return (DO) this;
102103
}
103104

105+
public DO setEnableDownloads(boolean enableDownloads) {
106+
setCapability(ENABLE_DOWNLOADS, enableDownloads);
107+
return (DO) this;
108+
}
109+
104110
@Override
105111
public Set<String> getCapabilityNames() {
106112
TreeSet<String> names = new TreeSet<>(super.getCapabilityNames());

java/src/org/openqa/selenium/remote/CapabilityType.java

+1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ public interface CapabilityType {
3030
String TIMEOUTS = "timeouts";
3131
String STRICT_FILE_INTERACTABILITY = "strictFileInteractability";
3232
String UNHANDLED_PROMPT_BEHAVIOUR = "unhandledPromptBehavior";
33+
String ENABLE_DOWNLOADS = "se:downloadsEnabled";
3334
}

java/test/org/openqa/selenium/chrome/ChromeOptionsTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ void canAddW3CCompliantOptions() {
8484
.setAcceptInsecureCerts(true)
8585
.setPageLoadStrategy(PageLoadStrategy.EAGER)
8686
.setStrictFileInteractability(true)
87+
.setEnableDownloads(true)
8788
.setImplicitWaitTimeout(Duration.ofSeconds(1))
8889
.setPageLoadTimeout(Duration.ofSeconds(2))
8990
.setScriptTimeout(Duration.ofSeconds(3));
@@ -96,6 +97,7 @@ void canAddW3CCompliantOptions() {
9697
assertThat(mappedOptions.get("acceptInsecureCerts")).isEqualTo(true);
9798
assertThat(mappedOptions.get("pageLoadStrategy")).hasToString("eager");
9899
assertThat(mappedOptions.get("strictFileInteractability")).isEqualTo(true);
100+
assertThat(mappedOptions.get("se:downloadsEnabled")).isEqualTo(true);
99101

100102
Map<String, Long> expectedTimeouts = new HashMap<>();
101103
expectedTimeouts.put("implicit", 1000L);

java/test/org/openqa/selenium/grid/router/RemoteWebDriverDownloadTest.java

+4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.openqa.selenium.PersistentCapabilities;
4343
import org.openqa.selenium.WebDriver;
4444
import org.openqa.selenium.WebDriverException;
45+
import org.openqa.selenium.chrome.ChromeOptions;
4546
import org.openqa.selenium.environment.webserver.NettyAppServer;
4647
import org.openqa.selenium.grid.config.TomlConfig;
4748
import org.openqa.selenium.grid.router.DeploymentTypes.Deployment;
@@ -67,6 +68,9 @@ class RemoteWebDriverDownloadTest {
6768
public void setupServers() {
6869
Browser browser = Browser.detect();
6970
assert browser != null;
71+
ChromeOptions options = new ChromeOptions();
72+
options.setEnableDownloads(true);
73+
7074
capabilities =
7175
new PersistentCapabilities(browser.getCapabilities())
7276
.setCapability("se:downloadsEnabled", true);

0 commit comments

Comments
 (0)