From febd025339cb73a59fefb3f0e3235f0e5a2cccfc Mon Sep 17 00:00:00 2001 From: Puja Jagani Date: Wed, 12 Jun 2024 13:27:02 +0530 Subject: [PATCH] Add preference to enable CDP in Firefox by default (#14091) Related to #11736 --- .../src/webdriver/Firefox/FirefoxOptions.cs | 3 ++ java/.idea/workspace.xml | 49 +++++++++++++++++++ .../selenium/firefox/FirefoxOptions.java | 4 ++ javascript/node/selenium-webdriver/firefox.js | 3 ++ .../test/firefox/options_test.js | 8 ++- py/selenium/webdriver/firefox/options.py | 3 ++ .../firefox/firefox_options_tests.py | 2 +- .../webdriver/remote/new_session_tests.py | 4 +- rb/lib/selenium/webdriver/firefox/options.rb | 3 ++ .../selenium/webdriver/firefox/driver_spec.rb | 7 ++- .../webdriver/firefox/options_spec.rb | 8 +-- 11 files changed, 84 insertions(+), 10 deletions(-) create mode 100644 java/.idea/workspace.xml diff --git a/dotnet/src/webdriver/Firefox/FirefoxOptions.cs b/dotnet/src/webdriver/Firefox/FirefoxOptions.cs index a5c8c0a5d494e..b2eb933805526 100644 --- a/dotnet/src/webdriver/Firefox/FirefoxOptions.cs +++ b/dotnet/src/webdriver/Firefox/FirefoxOptions.cs @@ -88,6 +88,9 @@ public FirefoxOptions() this.AddKnownCapabilityName(FirefoxOptions.FirefoxLegacyProfileCapability, "Profile property"); this.AddKnownCapabilityName(FirefoxOptions.FirefoxLegacyBinaryCapability, "BrowserExecutableLocation property"); this.AddKnownCapabilityName(FirefoxOptions.FirefoxEnableDevToolsProtocolCapability, "EnableDevToolsProtocol property"); + // Firefox 129 onwards the CDP protocol will not be enabled by default. Setting this preference will enable it. + // https://fxdx.dev/deprecating-cdp-support-in-firefox-embracing-the-future-with-webdriver-bidi/. + this.SetPreference("remote.active-protocols", 3); } /// diff --git a/java/.idea/workspace.xml b/java/.idea/workspace.xml new file mode 100644 index 0000000000000..c24b8f6be3837 --- /dev/null +++ b/java/.idea/workspace.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + 1717749164217 + + + + + + + \ No newline at end of file diff --git a/java/src/org/openqa/selenium/firefox/FirefoxOptions.java b/java/src/org/openqa/selenium/firefox/FirefoxOptions.java index ddde5e5402c51..6f514c79aec60 100644 --- a/java/src/org/openqa/selenium/firefox/FirefoxOptions.java +++ b/java/src/org/openqa/selenium/firefox/FirefoxOptions.java @@ -63,6 +63,10 @@ public FirefoxOptions() { setCapability(CapabilityType.BROWSER_NAME, FIREFOX.browserName()); setAcceptInsecureCerts(true); setCapability("moz:debuggerAddress", true); + // Firefox 129 onwards the CDP protocol will not be enabled by default. Setting this preference + // will enable it. + // https://fxdx.dev/deprecating-cdp-support-in-firefox-embracing-the-future-with-webdriver-bidi/. + addPreference("remote.active-protocols", 3); } public FirefoxOptions(Capabilities source) { diff --git a/javascript/node/selenium-webdriver/firefox.js b/javascript/node/selenium-webdriver/firefox.js index d3fd0c60e9280..f6cd1cf1e9d7e 100644 --- a/javascript/node/selenium-webdriver/firefox.js +++ b/javascript/node/selenium-webdriver/firefox.js @@ -246,6 +246,9 @@ class Options extends Capabilities { constructor(other) { super(other) this.setBrowserName(Browser.FIREFOX) + // Firefox 129 onwards the CDP protocol will not be enabled by default. Setting this preference will enable it. + // https://fxdx.dev/deprecating-cdp-support-in-firefox-embracing-the-future-with-webdriver-bidi/. + this.setPreference('remote.active-protocols', 3) } /** diff --git a/javascript/node/selenium-webdriver/test/firefox/options_test.js b/javascript/node/selenium-webdriver/test/firefox/options_test.js index 50f8441a05373..6e0706d3b12c2 100644 --- a/javascript/node/selenium-webdriver/test/firefox/options_test.js +++ b/javascript/node/selenium-webdriver/test/firefox/options_test.js @@ -87,7 +87,13 @@ suite( it('allows setting android activity', function () { let options = new firefox.Options().enableMobile() let firefoxOptions = options.firefoxOptions_() - assert.deepStrictEqual({ androidPackage: 'org.mozilla.firefox' }, firefoxOptions) + assert.deepStrictEqual( + { + androidPackage: 'org.mozilla.firefox', + prefs: { 'remote.active-protocols': 3 }, + }, + firefoxOptions, + ) }) }) diff --git a/py/selenium/webdriver/firefox/options.py b/py/selenium/webdriver/firefox/options.py index 1cb3a2bdd08a4..b16622b03dd93 100644 --- a/py/selenium/webdriver/firefox/options.py +++ b/py/selenium/webdriver/firefox/options.py @@ -41,6 +41,9 @@ def __init__(self) -> None: super().__init__() self._binary_location = "" self._preferences: dict = {} + # Firefox 129 onwards the CDP protocol will not be enabled by default. Setting this preference will enable it. + # https://fxdx.dev/deprecating-cdp-support-in-firefox-embracing-the-future-with-webdriver-bidi/. + self._preferences["remote.active-protocols"] = 3 self._profile = None self.log = Log() diff --git a/py/test/unit/selenium/webdriver/firefox/firefox_options_tests.py b/py/test/unit/selenium/webdriver/firefox/firefox_options_tests.py index a4a5ecbfbb09a..7086bd4778cdb 100644 --- a/py/test/unit/selenium/webdriver/firefox/firefox_options_tests.py +++ b/py/test/unit/selenium/webdriver/firefox/firefox_options_tests.py @@ -79,7 +79,7 @@ def test_set_proxy_isnt_in_moz_prefix(options): caps = options.to_capabilities() assert caps["proxy"]["proxyType"] == "manual" - assert caps.get("moz:firefoxOptions") is None + assert caps.get("moz:firefoxOptions") == {"prefs": {"remote.active-protocols": 3}} def test_raises_exception_if_proxy_is_not_proxy_object(options): diff --git a/py/test/unit/selenium/webdriver/remote/new_session_tests.py b/py/test/unit/selenium/webdriver/remote/new_session_tests.py index 95195f6e89a3f..f4fc9b3b39f7c 100644 --- a/py/test/unit/selenium/webdriver/remote/new_session_tests.py +++ b/py/test/unit/selenium/webdriver/remote/new_session_tests.py @@ -52,7 +52,7 @@ def test_works_as_context_manager(mocker): @pytest.mark.parametrize("browser_name", ["firefox", "chrome", "ie"]) -def test_accepts_options_to_remote_driver(mocker, browser_name): +def test_acepts_options_to_remote_driver(mocker, browser_name): options = import_module(f"selenium.webdriver.{browser_name}.options") mock = mocker.patch("selenium.webdriver.remote.webdriver.WebDriver.start_session") @@ -103,7 +103,7 @@ def test_first_match_when_2_different_option_types(): "browserName": "firefox", "acceptInsecureCerts": True, "moz:debuggerAddress": True, - "moz:firefoxOptions": {"args": ["foo"]}, + "moz:firefoxOptions": {"args": ["foo"], "prefs": {"remote.active-protocols": 3}}, }, ], } diff --git a/rb/lib/selenium/webdriver/firefox/options.rb b/rb/lib/selenium/webdriver/firefox/options.rb index 23a9014ba12b0..c702600b3bc28 100644 --- a/rb/lib/selenium/webdriver/firefox/options.rb +++ b/rb/lib/selenium/webdriver/firefox/options.rb @@ -64,6 +64,9 @@ def initialize(log_level: nil, **opts) @options[:args] ||= [] @options[:prefs] ||= {} + # Firefox 129 onwards the CDP protocol will not be enabled by default. Setting this preference will enable it. + # https://fxdx.dev/deprecating-cdp-support-in-firefox-embracing-the-future-with-webdriver-bidi/. + @options[:prefs]['remote.active-protocols'] = 3 @options[:env] ||= {} @options[:log] ||= {level: log_level} if log_level diff --git a/rb/spec/unit/selenium/webdriver/firefox/driver_spec.rb b/rb/spec/unit/selenium/webdriver/firefox/driver_spec.rb index 1d9a56b6e7f14..9c65604ce6aa4 100644 --- a/rb/spec/unit/selenium/webdriver/firefox/driver_spec.rb +++ b/rb/spec/unit/selenium/webdriver/firefox/driver_spec.rb @@ -38,7 +38,7 @@ module Firefox def expect_request(body: nil, endpoint: nil) body = (body || {capabilities: {alwaysMatch: {acceptInsecureCerts: true, browserName: 'firefox', - 'moz:firefoxOptions': {}, + 'moz:firefoxOptions': {prefs: {'remote.active-protocols' => 3}}, 'moz:debuggerAddress': true}}}).to_json endpoint ||= "#{service_manager.uri}/session" stub_request(:post, endpoint).with(body: body).to_return(valid_response) @@ -79,7 +79,10 @@ def expect_request(body: nil, endpoint: nil) opts = {args: ['-f']} expect_request(body: {capabilities: {alwaysMatch: {acceptInsecureCerts: true, browserName: 'firefox', - 'moz:firefoxOptions': opts, + 'moz:firefoxOptions': { + args: ['-f'], + prefs: {'remote.active-protocols' => 3} + }, 'moz:debuggerAddress': true}}}) expect { described_class.new(options: Options.new(**opts)) }.not_to raise_exception end diff --git a/rb/spec/unit/selenium/webdriver/firefox/options_spec.rb b/rb/spec/unit/selenium/webdriver/firefox/options_spec.rb index c849054f8dc12..911dd9ff9c99d 100644 --- a/rb/spec/unit/selenium/webdriver/firefox/options_spec.rb +++ b/rb/spec/unit/selenium/webdriver/firefox/options_spec.rb @@ -154,7 +154,7 @@ module Firefox options.add_preference('intl.accepted_languages', 'en-US') prefs = options.as_json['moz:firefoxOptions']['prefs'] - expected = {'intl.accepted_languages' => 'en-US'} + expected = {'intl.accepted_languages' => 'en-US', 'remote.active-protocols' => 3} expect(prefs).to eq(expected) end end @@ -185,7 +185,7 @@ module Firefox it 'returns empty options by default' do expect(options.as_json).to eq('browserName' => 'firefox', 'acceptInsecureCerts' => true, - 'moz:firefoxOptions' => {}, + 'moz:firefoxOptions' => {'prefs' => {'remote.active-protocols' => 3}}, 'moz:debuggerAddress' => true) end @@ -195,7 +195,7 @@ module Firefox 'browserName' => 'firefox', 'foo:bar' => {'foo' => 'bar'}, 'moz:debuggerAddress' => true, - 'moz:firefoxOptions' => {}) + 'moz:firefoxOptions' => {'prefs' => {'remote.active-protocols' => 3}}) end it 'converts to a json hash' do @@ -240,7 +240,7 @@ module Firefox 'moz:debuggerAddress' => true, key => {'args' => %w[foo bar], 'binary' => '/foo/bar', - 'prefs' => {'foo' => 'bar'}, + 'prefs' => {'foo' => 'bar', 'remote.active-protocols' => 3}, 'env' => {'FOO' => 'bar'}, 'profile' => 'encoded_profile', 'log' => {'level' => 'debug'},