Skip to content

Commit 6607c45

Browse files
committed
make augmentation of HasBiDi/HasDevTools lazy-loaded
Otherwise, command `new Augmenter().augment(remoteWebDriver)` fails immediately (even if I don't want to use CDP or BiDi).
1 parent b731bb4 commit 6607c45

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

java/src/org/openqa/selenium/bidi/BiDiProvider.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,16 @@ public Class<HasBiDi> getDescribedInterface() {
4444

4545
@Override
4646
public HasBiDi getImplementation(Capabilities caps, ExecuteMethod executeMethod) {
47+
return () -> {
48+
URI wsUri = getBiDiUrl(caps).orElseThrow(() -> new BiDiException("BiDi not supported"));
4749

48-
URI wsUri = getBiDiUrl(caps).orElseThrow(() -> new BiDiException("BiDi not supported"));
50+
HttpClient.Factory clientFactory = HttpClient.Factory.createDefault();
51+
ClientConfig wsConfig = ClientConfig.defaultConfig().baseUri(wsUri);
52+
HttpClient wsClient = clientFactory.createClient(wsConfig);
53+
Connection connection = new Connection(wsClient, wsUri.toString());
4954

50-
HttpClient.Factory clientFactory = HttpClient.Factory.createDefault();
51-
ClientConfig wsConfig = ClientConfig.defaultConfig().baseUri(wsUri);
52-
HttpClient wsClient = clientFactory.createClient(wsConfig);
53-
Connection connection = new Connection(wsClient, wsUri.toString());
54-
55-
return () -> Optional.of(new BiDi(connection));
55+
return Optional.of(new BiDi(connection));
56+
};
5657
}
5758

5859
private Optional<URI> getBiDiUrl(Capabilities caps) {

java/src/org/openqa/selenium/devtools/DevToolsProvider.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,16 @@ public Class<HasDevTools> getDescribedInterface() {
4242

4343
@Override
4444
public HasDevTools getImplementation(Capabilities caps, ExecuteMethod executeMethod) {
45-
Object cdpVersion = caps.getCapability("se:cdpVersion");
46-
String version = cdpVersion instanceof String ? (String) cdpVersion : caps.getBrowserVersion();
45+
return () -> {
46+
Object cdpVersion = caps.getCapability("se:cdpVersion");
47+
String version =
48+
cdpVersion instanceof String ? (String) cdpVersion : caps.getBrowserVersion();
4749

48-
CdpInfo info = new CdpVersionFinder().match(version).orElseGet(NoOpCdpInfo::new);
49-
Optional<DevTools> devTools =
50-
SeleniumCdpConnection.create(caps).map(conn -> new DevTools(info::getDomains, conn));
51-
52-
return () -> devTools;
50+
CdpInfo info = new CdpVersionFinder().match(version).orElseGet(NoOpCdpInfo::new);
51+
Optional<DevTools> devTools =
52+
SeleniumCdpConnection.create(caps).map(conn -> new DevTools(info::getDomains, conn));
53+
return devTools;
54+
};
5355
}
5456

5557
private String getCdpUrl(Capabilities caps) {

0 commit comments

Comments
 (0)