Skip to content

Commit e50a1ab

Browse files
authored
[java] Throw error when using custom client config with local driver (#10219)
1 parent 0f0ffa0 commit e50a1ab

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ public class RemoteWebDriverBuilder {
126126
private URI remoteHost = null;
127127
private DriverService driverService;
128128
private Credentials credentials = null;
129+
private boolean useCustomConfig;
129130
private Augmenter augmenter = new Augmenter();
130131

131132
RemoteWebDriverBuilder() {
@@ -273,6 +274,7 @@ public RemoteWebDriverBuilder config(ClientConfig config) {
273274
}
274275

275276
this.clientConfig = config;
277+
this.useCustomConfig = true;
276278

277279
return this;
278280
}
@@ -336,7 +338,13 @@ WebDriver getLocalDriver() {
336338
throw new SessionNotCreatedException("Unable to find matching driver for capabilities");
337339
}
338340

339-
return first.get().get();
341+
WebDriver localDriver = first.get().get();
342+
343+
if (localDriver != null && this.useCustomConfig) {
344+
throw new IllegalArgumentException("Custom client config is not supported in local drivers");
345+
}
346+
347+
return localDriver;
340348
}
341349

342350
/**

java/test/org/openqa/selenium/remote/RemoteWebDriverBuilderTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import java.io.IOException;
3939
import java.net.URI;
4040
import java.net.URL;
41+
import java.time.Duration;
4142
import java.util.ArrayList;
4243
import java.util.List;
4344
import java.util.Map;
@@ -304,6 +305,19 @@ public void shouldSetRemoteHostUriOnClientConfigIfSet() {
304305
assertThat(seen.get()).isEqualTo(uri);
305306
}
306307

308+
@Test
309+
public void shouldThrowErrorIfCustomConfigIfSetForLocalDriver() {
310+
ClientConfig config = ClientConfig.defaultConfig()
311+
.connectionTimeout(Duration.ofMinutes(5))
312+
.readTimeout(Duration.ofMinutes(4));
313+
314+
RemoteWebDriverBuilder builder = RemoteWebDriver.builder()
315+
.oneOf(new FirefoxOptions())
316+
.config(config);
317+
318+
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(builder::build);
319+
}
320+
307321
@Test
308322
public void shouldSetSessionIdFromW3CResponse() {
309323
RemoteWebDriver driver = (RemoteWebDriver) RemoteWebDriver.builder()

0 commit comments

Comments
 (0)