Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions java/src/org/openqa/selenium/chromium/ChromiumDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import java.util.logging.Logger;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
import org.openqa.selenium.BuildInfo;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.Credentials;
import org.openqa.selenium.HasAuthentication;
Expand All @@ -54,7 +53,6 @@
import org.openqa.selenium.devtools.Connection;
import org.openqa.selenium.devtools.DevTools;
import org.openqa.selenium.devtools.HasDevTools;
import org.openqa.selenium.devtools.noop.NoOpCdpInfo;
import org.openqa.selenium.internal.Require;
import org.openqa.selenium.json.TypeToken;
import org.openqa.selenium.logging.EventType;
Expand Down Expand Up @@ -162,22 +160,7 @@ protected ChromiumDriver(
}

CdpInfo cdpInfo =
new CdpVersionFinder()
.match(originalCapabilities.getBrowserVersion())
.orElseGet(
() -> {
LOG.warning(
String.format(
"Unable to find version of CDP to use for %s. You may need to include a"
+ " dependency on a specific version of the CDP using something"
+ " similar to `org.seleniumhq.selenium:selenium-devtools-v86:%s`"
+ " where the version (\"v86\") matches the version of the"
+ " chromium-based browser you're using and the version number of the"
+ " artifact is the same as Selenium's.",
originalCapabilities.getBrowserVersion(),
new BuildInfo().getReleaseLabel()));
return new NoOpCdpInfo();
});
new CdpVersionFinder().findMatchingVersion(originalCapabilities.getBrowserVersion());

devTools = connection.map(conn -> new DevTools(cdpInfo::getDomains, conn));

Expand Down
17 changes: 17 additions & 0 deletions java/src/org/openqa/selenium/devtools/CdpVersionFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import org.openqa.selenium.devtools.noop.NoOpCdpInfo;
import org.openqa.selenium.internal.Require;

public class CdpVersionFinder {
Expand Down Expand Up @@ -96,6 +97,22 @@ public Optional<CdpInfo> match(Map<String, Object> versionJson) {
/**
* Takes a `browserVersion` from a {@link org.openqa.selenium.Capabilities} instance and returns
* the matching CDP version.
*
* @param browserVersion A version of browser that we need to find the closest CDP version for
* @return closest available CDP version for given browser version - or {@link NoOpCdpInfo} if
* none was found
*/
public CdpInfo findMatchingVersion(String browserVersion) {
return match(browserVersion).orElseGet(() -> new NoOpCdpInfo(browserVersion, infos));
}
Comment thread
asolntsev marked this conversation as resolved.

/**
* Takes a `browserVersion` from a {@link org.openqa.selenium.Capabilities} instance and returns
* the matching CDP version.
*
* @param browserVersion A version of browser that we need to find a closest CDP version for
* @return closest available CDP version for given browser version - or {@link Optional#empty()}
* if none was found
*/
public Optional<CdpInfo> match(String browserVersion) {
Require.nonNull("Browser version", browserVersion);
Expand Down
3 changes: 1 addition & 2 deletions java/src/org/openqa/selenium/devtools/DevToolsProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.jspecify.annotations.Nullable;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.concurrent.Lazy;
import org.openqa.selenium.devtools.noop.NoOpCdpInfo;
import org.openqa.selenium.remote.AugmenterProvider;
import org.openqa.selenium.remote.ExecuteMethod;
import org.openqa.selenium.remote.RemoteExecuteMethod;
Expand Down Expand Up @@ -74,7 +73,7 @@ private DevTools establishDevToolsConnection(Capabilities caps, ExecuteMethod ex
Object cdpVersion = caps.getCapability("se:cdpVersion");
String version = cdpVersion instanceof String ? (String) cdpVersion : caps.getBrowserVersion();

CdpInfo info = new CdpVersionFinder().match(version).orElseGet(NoOpCdpInfo::new);
CdpInfo info = new CdpVersionFinder().findMatchingVersion(version);
return SeleniumCdpConnection.create(
caps, ((RemoteExecuteMethod) executeMethod).getWrappedDriver().getClientConfig())
.map(conn -> new DevTools(info::getDomains, conn))
Expand Down
9 changes: 9 additions & 0 deletions java/src/org/openqa/selenium/devtools/noop/NoOpCdpInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,20 @@

package org.openqa.selenium.devtools.noop;

import java.util.Collection;
import org.openqa.selenium.devtools.CdpInfo;

public class NoOpCdpInfo extends CdpInfo {

/**
* @deprecated use {@link #NoOpCdpInfo(String, Collection)} instead
*/
@Deprecated(forRemoval = true)
public NoOpCdpInfo() {
super(1, dt -> new NoOpDomains());
}

public NoOpCdpInfo(String browserVersion, Collection<CdpInfo> availableCdpImplementations) {
super(1, dt -> new NoOpDomains(browserVersion, availableCdpImplementations));
}
Comment thread
asolntsev marked this conversation as resolved.
}
59 changes: 45 additions & 14 deletions java/src/org/openqa/selenium/devtools/noop/NoOpDomains.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,56 +17,87 @@

package org.openqa.selenium.devtools.noop;

import static java.util.Collections.emptyList;
import static java.util.stream.Collectors.toSet;

import java.util.Collection;
import java.util.Set;
import org.openqa.selenium.BuildInfo;
import org.openqa.selenium.devtools.CdpInfo;
import org.openqa.selenium.devtools.DevToolsException;
import org.openqa.selenium.devtools.idealized.Domains;
import org.openqa.selenium.devtools.idealized.Events;
import org.openqa.selenium.devtools.idealized.Javascript;
import org.openqa.selenium.devtools.idealized.Network;
import org.openqa.selenium.devtools.idealized.log.Log;
import org.openqa.selenium.devtools.idealized.target.Target;
import org.openqa.selenium.internal.Require;

public class NoOpDomains implements Domains {

private static final BuildInfo INFO = new BuildInfo();

private static final String WARNING =
String.format(
"You are using a no-op implementation of the CDP. The most likely reason"
+ " for this is that Selenium was unable to find an implementation of the "
+ "CDP protocol that matches your browser. Please be sure to include an "
+ "implementation on the classpath, possibly by adding a new (maven) "
+ "dependency of `org.seleniumhq.selenium:selenium-devtools-vNN:%s` where "
+ "`NN` matches the major version of the browser you're using.",
INFO.getReleaseLabel());
"You are using a no-op implementation of the CDP. The most likely reason"
+ " for this is that Selenium was unable to find an implementation of the "
+ "CDP protocol that matches your browser. "
+ "Browser version: %s.%n"
+ "Available CDP implementations: %s.%n"
+ "Please be sure to include an "
+ "implementation on the classpath, possibly by adding a new (maven) "
+ "dependency of `org.seleniumhq.selenium:selenium-devtools-vNN:%s` where "
+ "`NN` matches the major version of the browser you're using.";

private final String browserVersion;
private final Collection<CdpInfo> availableCdpImplementations;

/**
* @deprecated Use {@link #NoOpDomains(String, Collection)} instead.
*/
@Deprecated(forRemoval = true)
public NoOpDomains() {
this("?", emptyList());
}

public NoOpDomains(String browserVersion, Collection<CdpInfo> availableCdpImplementations) {
this.browserVersion = browserVersion;
this.availableCdpImplementations =
Require.nonNull("Available CDP implementations", availableCdpImplementations);
}
Comment thread
asolntsev marked this conversation as resolved.
Comment thread
asolntsev marked this conversation as resolved.

@Override
public Events<?, ?> events() {
throw new DevToolsException(WARNING);
throw new DevToolsException(message());
}

@Override
public Javascript<?, ?> javascript() {
throw new DevToolsException(WARNING);
throw new DevToolsException(message());
}

@Override
public Network<?, ?> network() {
throw new DevToolsException(WARNING);
throw new DevToolsException(message());
}

@Override
public Target target() {
throw new DevToolsException(WARNING);
throw new DevToolsException(message());
}

@Override
public Log log() {
throw new DevToolsException(WARNING);
throw new DevToolsException(message());
}

@Override
public void disableAll() {
throw new DevToolsException(WARNING);
throw new DevToolsException(message());
}

private String message() {
Set<Integer> cdpVersions =
availableCdpImplementations.stream().map(info -> info.getMajorVersion()).collect(toSet());
return String.format(WARNING, browserVersion, cdpVersions, INFO.getReleaseLabel());
}
Comment thread
asolntsev marked this conversation as resolved.
}
Loading