Skip to content

Commit 3ef95ef

Browse files
authored
[java] Allow local driver tests to not depend on actual webdriver implementations
1 parent c718c0d commit 3ef95ef

4 files changed

Lines changed: 76 additions & 4 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ WebDriver getLocalDriver() {
341341
WebDriver localDriver = first.get().get();
342342

343343
if (localDriver != null && this.useCustomConfig) {
344-
throw new IllegalArgumentException("Custom client config is not supported in local drivers");
344+
throw new IllegalArgumentException("ClientConfig instances do not work for Local Drivers");
345345
}
346346

347347
return localDriver;

java/test/org/openqa/selenium/remote/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ java_test_suite(
2121
"no-sandbox",
2222
],
2323
deps = [
24+
"//java:auto-service",
2425
"//java/src/org/openqa/selenium:core",
2526
"//java/src/org/openqa/selenium/chrome",
2627
"//java/src/org/openqa/selenium/firefox",
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package org.openqa.selenium.remote;
2+
3+
import static org.openqa.selenium.remote.CapabilityType.BROWSER_NAME;
4+
5+
import com.google.auto.service.AutoService;
6+
7+
import org.openqa.selenium.Capabilities;
8+
import org.openqa.selenium.ImmutableCapabilities;
9+
import org.openqa.selenium.SessionNotCreatedException;
10+
import org.openqa.selenium.WebDriver;
11+
import org.openqa.selenium.WebDriverInfo;
12+
13+
import java.util.Optional;
14+
15+
@AutoService(WebDriverInfo.class)
16+
public class FakeWebDriverInfo implements WebDriverInfo {
17+
18+
@Override
19+
public String getDisplayName() {
20+
return "selenium-test";
21+
}
22+
23+
@Override
24+
public Capabilities getCanonicalCapabilities() {
25+
return new ImmutableCapabilities(BROWSER_NAME, "selenium-test");
26+
}
27+
28+
@Override
29+
public boolean isSupporting(Capabilities capabilities) {
30+
return true;
31+
}
32+
33+
@Override
34+
public boolean isSupportingCdp() {
35+
return false;
36+
}
37+
38+
@Override
39+
public boolean isAvailable() {
40+
return true;
41+
}
42+
43+
@Override
44+
public int getMaximumSimultaneousSessions() {
45+
return Runtime.getRuntime().availableProcessors();
46+
}
47+
48+
@Override
49+
public Optional<WebDriver> createDriver(Capabilities capabilities)
50+
throws SessionNotCreatedException {
51+
52+
return Optional.of(new FakeWebDriver());
53+
}
54+
55+
private static class FakeWebDriver extends RemoteWebDriver {
56+
57+
@Override
58+
protected void startSession(Capabilities capabilities) {
59+
// no-op
60+
}
61+
62+
@Override
63+
public void quit() {
64+
// no-op
65+
}
66+
}
67+
}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import static java.util.Collections.singletonList;
5252
import static org.assertj.core.api.Assertions.assertThat;
5353
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
54+
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
5455
import static org.openqa.selenium.json.Json.JSON_UTF_8;
5556
import static org.openqa.selenium.json.Json.MAP_TYPE;
5657
import static org.openqa.selenium.remote.Browser.CHROME;
@@ -312,10 +313,13 @@ public void shouldThrowErrorIfCustomConfigIfSetForLocalDriver() {
312313
.readTimeout(Duration.ofMinutes(4));
313314

314315
RemoteWebDriverBuilder builder = RemoteWebDriver.builder()
315-
.oneOf(new FirefoxOptions())
316-
.config(config);
316+
.oneOf(new ImmutableCapabilities("browser", "selenium-test"))
317+
.config(config)
318+
.connectingWith(clientConfig -> req -> CANNED_SESSION_RESPONSE);
317319

318-
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(builder::build);
320+
assertThatIllegalArgumentException()
321+
.isThrownBy(builder::build)
322+
.withMessage("ClientConfig instances do not work for Local Drivers");
319323
}
320324

321325
@Test

0 commit comments

Comments
 (0)