Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java]: allow setting custom timeout for DevTools #14931

Merged
merged 5 commits into from
Jan 10, 2025
Merged
Changes from 2 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
16 changes: 15 additions & 1 deletion java/src/org/openqa/selenium/devtools/DevTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,19 @@ public class DevTools implements Closeable {
private static final Logger LOG = Logger.getLogger(DevTools.class.getName());

private final Domains protocol;
private final Duration timeout = Duration.ofSeconds(10);
private Duration timeout = Duration.ofSeconds(10);
private final Connection connection;
private SessionID cdpSession = null;

public DevTools(Function<DevTools, Domains> protocol, Connection connection) {
this(protocol, connection, Duration.ofSeconds(10));
}

// overloaded constructor for setting timeout
public DevTools(Function<DevTools, Domains> protocol, Connection connection, Duration timeout) {
this.connection = Require.nonNull("WebSocket connection", connection);
this.protocol = Require.nonNull("CDP protocol", protocol).apply(this);
setTimeout(timeout);
}

public Domains getDomains() {
Expand Down Expand Up @@ -212,4 +218,12 @@ private Throwable unwrapCause(ExecutionException e) {
public SessionID getCdpSession() {
return cdpSession;
}

public void setTimeout(Duration timeout) {
Require.nonNull("Timeout duration", timeout);
if (timeout.isNegative() || timeout.isZero()) {
throw new IllegalArgumentException("Timeout must be positive");
}
this.timeout = timeout;
}
}