From 5d4cfc1e1ed1e59e2f936af971e902aedfc0c894 Mon Sep 17 00:00:00 2001 From: Diego Molina Date: Thu, 2 May 2024 10:27:34 +0200 Subject: [PATCH] [java] Improving error message for BiDi connection Either when `webSocketUrl` is not set or the browser version does not support BiDi. Related to #13896 [skip ci] --- .../org/openqa/selenium/chromium/ChromiumDriver.java | 7 +++++-- .../org/openqa/selenium/firefox/FirefoxDriver.java | 12 ++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/java/src/org/openqa/selenium/chromium/ChromiumDriver.java b/java/src/org/openqa/selenium/chromium/ChromiumDriver.java index 6f282607c7166..7a87460878313 100644 --- a/java/src/org/openqa/selenium/chromium/ChromiumDriver.java +++ b/java/src/org/openqa/selenium/chromium/ChromiumDriver.java @@ -347,13 +347,16 @@ public Optional maybeGetDevTools() { } private Optional createBiDi(Optional 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); diff --git a/java/src/org/openqa/selenium/firefox/FirefoxDriver.java b/java/src/org/openqa/selenium/firefox/FirefoxDriver.java index 36111d411c9a0..1745564ffdaf8 100644 --- a/java/src/org/openqa/selenium/firefox/FirefoxDriver.java +++ b/java/src/org/openqa/selenium/firefox/FirefoxDriver.java @@ -354,14 +354,16 @@ public DevTools getDevTools() { } private Optional createBiDi(Optional 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); @@ -380,8 +382,10 @@ public Optional 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()