Skip to content

Commit ddfcd94

Browse files
committed
[cdp] Handle the case when the first window closes
This means that we need to make the remote webdriver aware of the CDP protocol, and that makes me very sad indeed.
1 parent fa37d18 commit ddfcd94

File tree

26 files changed

+194
-53
lines changed

26 files changed

+194
-53
lines changed

Rakefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ JAVA_RELEASE_TARGETS = %w[
106106
//java/src/org/openqa/selenium/devtools/v85:v85.publish
107107
//java/src/org/openqa/selenium/devtools/v93:v93.publish
108108
//java/src/org/openqa/selenium/devtools/v94:v94.publish
109-
//java/src/org/openqa/selenium/devtools:devtools.publish
110109
//java/src/org/openqa/selenium/edge:edge.publish
111110
//java/src/org/openqa/selenium/firefox/xpi:xpi.publish
112111
//java/src/org/openqa/selenium/firefox:firefox.publish

java/CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ v4.0.0-rc-2
1414
* Add strongly-typed methods for setting timeouts and other w3c
1515
capabilities on the base options class.
1616
* Enable live view for Dynamic Grid
17+
* Merged devtools maven artifact into the main remote driver
1718

1819
v4.0.0-rc-1
1920
===========

java/src/org/openqa/selenium/chrome/BUILD.bazel

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ java_export(
1515
"//java:auto-service",
1616
"//java/src/org/openqa/selenium:core",
1717
"//java/src/org/openqa/selenium/chromium",
18-
"//java/src/org/openqa/selenium/devtools",
1918
"//java/src/org/openqa/selenium/json",
2019
"//java/src/org/openqa/selenium/remote",
21-
"//java/src/org/openqa/selenium/remote/http",
2220
artifact("com.google.guava:guava"),
2321
],
2422
)

java/src/org/openqa/selenium/chromium/BUILD.bazel

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ java_export(
1111
"//visibility:public",
1212
],
1313
exports = [
14-
"//java/src/org/openqa/selenium/devtools",
14+
"//java/src/org/openqa/selenium/remote",
1515
],
1616
deps = [
1717
"//java:auto-service",
18-
"//java/src/org/openqa/selenium/devtools",
1918
"//java/src/org/openqa/selenium/json",
2019
"//java/src/org/openqa/selenium/remote",
2120
artifact("com.google.guava:guava"),

java/src/org/openqa/selenium/chromium/ChromiumDriver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ public Map<String, Object> executeCdpCommand(String commandName, Map<String, Obj
217217
}
218218

219219
@Override
220-
public DevTools getDevTools() {
221-
return devTools.orElseThrow(() -> new WebDriverException("Unable to create DevTools connection"));
220+
public Optional<DevTools> maybeGetDevTools() {
221+
return devTools;
222222
}
223223

224224
public String getCastSinks() {

java/src/org/openqa/selenium/devtools/BUILD.bazel

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
load("@rules_jvm_external//:defs.bzl", "artifact")
22
load("//common:defs.bzl", "copy_file")
3-
load("//java:defs.bzl", "java_binary", "java_export", "java_library")
4-
load("//java:version.bzl", "SE_VERSION")
3+
load("//java:defs.bzl", "java_binary", "java_library")
54

65
GENERATOR_SOURCES = [
76
"CdpClientGenerator.java",
@@ -33,7 +32,25 @@ copy_file(
3332
out = "mutation-listener.js",
3433
)
3534

36-
java_export(
35+
AUGMENTER_SRCS = [
36+
"DevToolsProvider.java",
37+
]
38+
39+
java_library(
40+
name = "augmenter",
41+
srcs = AUGMENTER_SRCS,
42+
visibility = [
43+
"//java/src/org/openqa/selenium/remote:__pkg__",
44+
],
45+
deps = [
46+
":devtools",
47+
"//java:auto-service",
48+
"//java/src/org/openqa/selenium:core",
49+
"//java/src/org/openqa/selenium/remote:api",
50+
],
51+
)
52+
53+
java_library(
3754
name = "devtools",
3855
srcs = glob(
3956
[
@@ -42,18 +59,13 @@ java_export(
4259
"idealized/**/*.java",
4360
"noop/*.java",
4461
],
45-
exclude = PROTOTYPE_SOURCES + GENERATOR_SOURCES,
62+
exclude = AUGMENTER_SRCS + GENERATOR_SOURCES + PROTOTYPE_SOURCES,
4663
),
47-
maven_coordinates = "org.seleniumhq.selenium:selenium-devtools:%s" % SE_VERSION,
48-
opens_to = [
49-
"org.openqa.selenium.json",
50-
],
51-
pom_template = "//java/src/org/openqa/selenium:template-pom",
5264
resources = [
5365
":mutation-listener",
5466
],
5567
visibility = [
56-
"//visibility:public",
68+
"//java/src/org/openqa/selenium/remote:__pkg__",
5769
],
5870
exports = [
5971
":devtools-prototypes",
@@ -63,7 +75,7 @@ java_export(
6375
"//java:auto-service",
6476
"//java/src/org/openqa/selenium:core",
6577
"//java/src/org/openqa/selenium/json",
66-
"//java/src/org/openqa/selenium/remote",
78+
"//java/src/org/openqa/selenium/remote/http",
6779
artifact("com.google.guava:guava"),
6880
],
6981
)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ public Domains getDomains() {
5353

5454
@Override
5555
public void close() {
56+
disconnectSession();
57+
}
58+
59+
public void disconnectSession() {
5660
if (cdpSession != null) {
5761
SessionID id = cdpSession;
5862
cdpSession = null;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public HasDevTools getImplementation(Capabilities caps, ExecuteMethod executeMet
4747
CdpInfo info = new CdpVersionFinder().match(version).orElseGet(NoOpCdpInfo::new);
4848
Optional<DevTools> devTools = SeleniumCdpConnection.create(caps).map(conn -> new DevTools(info::getDomains, conn));
4949

50-
return () -> devTools.orElseThrow(() -> new IllegalStateException("Unable to create connection to " + caps));
50+
return () -> devTools;
5151
}
5252

5353
private String getCdpUrl(Capabilities caps) {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@
1717

1818
package org.openqa.selenium.devtools;
1919

20+
import java.util.Optional;
21+
2022
public interface HasDevTools {
2123

22-
DevTools getDevTools();
24+
default DevTools getDevTools() {
25+
return maybeGetDevTools().orElseThrow(() -> new DevToolsException("Unable to create DevTools connection"));
26+
}
27+
28+
Optional<DevTools> maybeGetDevTools();
2329

2430
}

java/src/org/openqa/selenium/devtools/idealized/target/Target.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.openqa.selenium.devtools.idealized.target;
1919

2020
import org.openqa.selenium.devtools.Command;
21+
import org.openqa.selenium.devtools.Event;
2122
import org.openqa.selenium.devtools.idealized.target.model.SessionID;
2223
import org.openqa.selenium.devtools.idealized.target.model.TargetID;
2324
import org.openqa.selenium.devtools.idealized.target.model.TargetInfo;
@@ -37,4 +38,6 @@ public interface Target {
3738
Command<SessionID> attachToTarget(TargetID targetId);
3839

3940
Command<Void> setAutoAttach();
41+
42+
Event<TargetID> detached();
4043
}

0 commit comments

Comments
 (0)