Skip to content

Commit

Permalink
[java] Improving error message for BiDi connection
Browse files Browse the repository at this point in the history
Either when `webSocketUrl` is not set or the
browser version does not support BiDi.

Related to #13896

[skip ci]
  • Loading branch information
diemol committed May 2, 2024
1 parent 1e0cde1 commit 5d4cfc1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
7 changes: 5 additions & 2 deletions java/src/org/openqa/selenium/chromium/ChromiumDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,16 @@ public Optional<DevTools> maybeGetDevTools() {
}

private Optional<BiDi> createBiDi(Optional<URI> biDiUri) {
if (!biDiUri.isPresent()) {
if (biDiUri.isEmpty()) {
return Optional.empty();
}

URI wsUri =
biDiUri.orElseThrow(
() -> new BiDiException("This version of Chromium driver does not support BiDi"));
() ->
new BiDiException(
"Check if this browser version supports BiDi and if the 'webSocketUrl: true'"
+ " capability is set."));

HttpClient.Factory clientFactory = HttpClient.Factory.createDefault();
ClientConfig wsConfig = ClientConfig.defaultConfig().baseUri(wsUri);
Expand Down
12 changes: 8 additions & 4 deletions java/src/org/openqa/selenium/firefox/FirefoxDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,14 +354,16 @@ public DevTools getDevTools() {
}

private Optional<BiDi> createBiDi(Optional<URI> biDiUri) {
if (!biDiUri.isPresent()) {
if (biDiUri.isEmpty()) {
return Optional.empty();
}

URI wsUri =
biDiUri.orElseThrow(
() ->
new BiDiException("This version of Firefox or geckodriver does not support BiDi"));
new BiDiException(
"Check if this browser version supports BiDi and if the 'webSocketUrl: true'"
+ " capability is set."));

HttpClient.Factory clientFactory = HttpClient.Factory.createDefault();
ClientConfig wsConfig = ClientConfig.defaultConfig().baseUri(wsUri);
Expand All @@ -380,8 +382,10 @@ public Optional<BiDi> maybeGetBiDi() {

@Override
public BiDi getBiDi() {
if (!biDiUri.isPresent()) {
throw new BiDiException("This version of Firefox or geckodriver does not support Bidi");
if (biDiUri.isEmpty()) {
throw new BiDiException(
"Check if this browser version supports BiDi and if the 'webSocketUrl: true' capability"
+ " is set.");
}

return maybeGetBiDi()
Expand Down

0 comments on commit 5d4cfc1

Please sign in to comment.