From 0e8afacd63c30e7298f803b401aa9265f715de18 Mon Sep 17 00:00:00 2001 From: Puja Jagani Date: Wed, 22 May 2024 17:49:08 +0530 Subject: [PATCH] [java] Add convenience for enabling BiDi Related to #13991 --- java/src/org/openqa/selenium/chromium/ChromiumOptions.java | 5 +++++ java/src/org/openqa/selenium/firefox/FirefoxOptions.java | 5 +++++ .../org/openqa/selenium/bidi/BiDiSessionCleanUpTest.java | 4 ++-- java/test/org/openqa/selenium/testing/drivers/Browser.java | 6 +++--- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/java/src/org/openqa/selenium/chromium/ChromiumOptions.java b/java/src/org/openqa/selenium/chromium/ChromiumOptions.java index 6846aedfc618c..2954d67f549f0 100644 --- a/java/src/org/openqa/selenium/chromium/ChromiumOptions.java +++ b/java/src/org/openqa/selenium/chromium/ChromiumOptions.java @@ -186,6 +186,11 @@ public T addEncodedExtensions(List encoded) { return (T) this; } + public T enableBiDi() { + setCapability("webSocketUrl", true); + return (T) this; + } + /** * Sets an experimental option. Useful for new ChromeDriver options not yet exposed through the * {@link ChromiumOptions} API. diff --git a/java/src/org/openqa/selenium/firefox/FirefoxOptions.java b/java/src/org/openqa/selenium/firefox/FirefoxOptions.java index 0c8620931b4a3..ddde5e5402c51 100644 --- a/java/src/org/openqa/selenium/firefox/FirefoxOptions.java +++ b/java/src/org/openqa/selenium/firefox/FirefoxOptions.java @@ -294,6 +294,11 @@ private FirefoxOptions setFirefoxOption(String key, Object value) { return this; } + public FirefoxOptions enableBiDi() { + setCapability("webSocketUrl", true); + return this; + } + @Override protected Set getExtraCapabilityNames() { Set names = new TreeSet<>(); diff --git a/java/test/org/openqa/selenium/bidi/BiDiSessionCleanUpTest.java b/java/test/org/openqa/selenium/bidi/BiDiSessionCleanUpTest.java index 090767dd89c1c..a132a501d0e5f 100644 --- a/java/test/org/openqa/selenium/bidi/BiDiSessionCleanUpTest.java +++ b/java/test/org/openqa/selenium/bidi/BiDiSessionCleanUpTest.java @@ -36,7 +36,7 @@ class BiDiSessionCleanUpTest { void shouldNotCloseBiDiSessionIfOneWindowIsClosed() { FirefoxOptions options = (FirefoxOptions) Browser.FIREFOX.getCapabilities(); // Enable BiDi - options.setCapability("webSocketUrl", true); + options.enableBiDi(); driver = new FirefoxDriver(options); @@ -64,7 +64,7 @@ void shouldNotCloseBiDiSessionIfOneWindowIsClosed() { void shouldCloseBiDiSessionIfLastWindowIsClosed() { FirefoxOptions options = (FirefoxOptions) Browser.FIREFOX.getCapabilities(); // Enable BiDi - options.setCapability("webSocketUrl", true); + options.enableBiDi(); driver = new FirefoxDriver(options); diff --git a/java/test/org/openqa/selenium/testing/drivers/Browser.java b/java/test/org/openqa/selenium/testing/drivers/Browser.java index 54eda7a045c28..0675dbe04b32b 100644 --- a/java/test/org/openqa/selenium/testing/drivers/Browser.java +++ b/java/test/org/openqa/selenium/testing/drivers/Browser.java @@ -59,7 +59,7 @@ public Capabilities getCapabilities() { prefs.put("exited_cleanly", true); options.setExperimentalOption("prefs", prefs); - options.setCapability("webSocketUrl", true); + options.enableBiDi(); return options; } @@ -90,7 +90,7 @@ public Capabilities getCapabilities() { prefs.put("exited_cleanly", true); options.setExperimentalOption("prefs", prefs); - options.setCapability("webSocketUrl", true); + options.enableBiDi(); return options; } @@ -129,7 +129,7 @@ public Capabilities getCapabilities() { options.addArguments("-headless"); } - options.setCapability("webSocketUrl", true); + options.enableBiDi(); return options; }