Skip to content

Commit

Permalink
[java] Allow resuing devtools instance with JDK 11 client (#13165)
Browse files Browse the repository at this point in the history
Fixes #12882
  • Loading branch information
pujagani committed Nov 17, 2023
1 parent 3041af3 commit 5138a9c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 12 additions & 1 deletion java/src/org/openqa/selenium/devtools/Connection.java
Expand Up @@ -24,6 +24,8 @@

import java.io.Closeable;
import java.io.StringReader;
import java.net.URI;
import java.net.URISyntaxException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -51,6 +53,7 @@
import org.openqa.selenium.json.Json;
import org.openqa.selenium.json.JsonInput;
import org.openqa.selenium.json.JsonOutput;
import org.openqa.selenium.remote.http.ClientConfig;
import org.openqa.selenium.remote.http.HttpClient;
import org.openqa.selenium.remote.http.HttpRequest;
import org.openqa.selenium.remote.http.WebSocket;
Expand All @@ -72,7 +75,7 @@ public class Connection implements Closeable {
new ConcurrentHashMap<>();
private final ReadWriteLock callbacksLock = new ReentrantReadWriteLock(true);
private final Map<Event<?>, List<Consumer<?>>> eventCallbacks = new HashMap<>();
private final HttpClient client;
private HttpClient client;
private final String url;
private final AtomicBoolean isClosed;

Expand All @@ -90,6 +93,14 @@ boolean isClosed() {
}

void reopen() {
HttpClient.Factory clientFactory = HttpClient.Factory.createDefault();
ClientConfig wsConfig = null;
try {
wsConfig = ClientConfig.defaultConfig().baseUri(new URI(this.url));
} catch (URISyntaxException e) {
LOG.warning(e.getMessage());
}
this.client = clientFactory.createClient(wsConfig);
this.socket = this.client.openSocket(new HttpRequest(GET, url), new Listener());
}

Expand Down
2 changes: 0 additions & 2 deletions java/test/org/openqa/selenium/devtools/DevToolsReuseTest.java
Expand Up @@ -19,15 +19,13 @@

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.Augmenter;

class DevToolsReuseTest extends DevToolsTestBase {

@Test
@Disabled("JDK HTTP Client cannot get reused")
public void shouldBeAbleToCloseDevToolsAndCreateNewInstance() {
WebDriver driver = new Augmenter().augment(this.driver);

Expand Down

0 comments on commit 5138a9c

Please sign in to comment.