From 8c317d89e6b88bb5a59c9e38a0485f3c15fa804e Mon Sep 17 00:00:00 2001 From: titusfortner Date: Sat, 22 Mar 2025 11:12:31 -0700 Subject: [PATCH 1/6] [build] allow tests tagged exclusive-if-local to run on rbe --- .bazelrc.remote | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bazelrc.remote b/.bazelrc.remote index 40f864f95cda2..7b50bef8b48f1 100644 --- a/.bazelrc.remote +++ b/.bazelrc.remote @@ -31,7 +31,7 @@ build:remote --disk_cache= build:remote --incompatible_enable_cc_toolchain_resolution build:remote --action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 test:remote --test_env=DISPLAY=:99.0 -test:remote --test_tag_filters=-exclusive-if-local,-skip-rbe,-remote +test:remote --test_tag_filters=-skip-rbe,-remote # Env vars we can hard code build:remote --action_env=HOME=/home/dev From 41e2533a0c1771423798c48a590497a2a880b408 Mon Sep 17 00:00:00 2001 From: aguspe Date: Mon, 14 Jul 2025 21:45:51 +0200 Subject: [PATCH 2/6] Adding options --- rb/lib/selenium/webdriver/bidi.rb | 4 ++-- rb/lib/selenium/webdriver/common/options.rb | 4 +++- rb/lib/selenium/webdriver/common/websocket_connection.rb | 7 +++++-- .../lib/selenium/webdriver/common/websocket_connection.rbs | 2 ++ 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/rb/lib/selenium/webdriver/bidi.rb b/rb/lib/selenium/webdriver/bidi.rb index 4c8ca37b4f8d2..f0faa1df1bd56 100644 --- a/rb/lib/selenium/webdriver/bidi.rb +++ b/rb/lib/selenium/webdriver/bidi.rb @@ -31,8 +31,8 @@ class BiDi autoload :InterceptedAuth, 'selenium/webdriver/bidi/network/intercepted_auth' autoload :InterceptedItem, 'selenium/webdriver/bidi/network/intercepted_item' - def initialize(url:) - @ws = WebSocketConnection.new(url: url) + def initialize(url:, **) + @ws = WebSocketConnection.new(url: url, **) end def close diff --git a/rb/lib/selenium/webdriver/common/options.rb b/rb/lib/selenium/webdriver/common/options.rb index bddb91063737b..1297f386e15e8 100644 --- a/rb/lib/selenium/webdriver/common/options.rb +++ b/rb/lib/selenium/webdriver/common/options.rb @@ -26,6 +26,8 @@ class Options GRID_OPTIONS = %i[enable_downloads].freeze + WEBSOCKET_OPTIONS = %i[ws_response_timeout ws_response_interval].freeze + class << self attr_reader :driver_path @@ -52,7 +54,7 @@ def safari(**) end def set_capabilities - (W3C_OPTIONS + GRID_OPTIONS + self::CAPABILITIES.keys).each do |key| + (W3C_OPTIONS + GRID_OPTIONS + WEBSOCKET_OPTIONS + self::CAPABILITIES.keys).each do |key| next if method_defined? key define_method key do diff --git a/rb/lib/selenium/webdriver/common/websocket_connection.rb b/rb/lib/selenium/webdriver/common/websocket_connection.rb index 26f02ebc9bf1c..1ecf8a7e6fb7d 100644 --- a/rb/lib/selenium/webdriver/common/websocket_connection.rb +++ b/rb/lib/selenium/webdriver/common/websocket_connection.rb @@ -32,9 +32,12 @@ class WebSocketConnection MAX_LOG_MESSAGE_SIZE = 9999 - def initialize(url:) + def initialize(url:, options: {}) @callback_threads = ThreadGroup.new + @response_timeout = options.fetch(:response_timeout, RESPONSE_WAIT_TIMEOUT) + @response_interval = options.fetch(:response_interval, RESPONSE_WAIT_INTERVAL) + @session_id = nil @url = url @@ -147,7 +150,7 @@ def callback_thread(params) end def wait - @wait ||= Wait.new(timeout: RESPONSE_WAIT_TIMEOUT, interval: RESPONSE_WAIT_INTERVAL) + @wait ||= Wait.new(timeout: @response_timeout, interval: @response_interval) end def socket diff --git a/rb/sig/lib/selenium/webdriver/common/websocket_connection.rbs b/rb/sig/lib/selenium/webdriver/common/websocket_connection.rbs index 98ac289f081ed..a97bd98ea05b7 100644 --- a/rb/sig/lib/selenium/webdriver/common/websocket_connection.rbs +++ b/rb/sig/lib/selenium/webdriver/common/websocket_connection.rbs @@ -5,6 +5,8 @@ module Selenium @callback_threads: untyped + @response_interval: Float + @response_timeout: Integer @session_id: untyped @url: untyped From 69847e9d37bb987bc3d6d2e0f6dfda4f0f00a3eb Mon Sep 17 00:00:00 2001 From: aguspe Date: Wed, 16 Jul 2025 15:23:46 +0200 Subject: [PATCH 3/6] Pass waits to bidi bridge --- rb/lib/selenium/webdriver/common/driver.rb | 17 +++++++++++++++-- rb/lib/selenium/webdriver/remote/bidi_bridge.rb | 7 ++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/rb/lib/selenium/webdriver/common/driver.rb b/rb/lib/selenium/webdriver/common/driver.rb index 94a29513e2752..32c40655f1e14 100644 --- a/rb/lib/selenium/webdriver/common/driver.rb +++ b/rb/lib/selenium/webdriver/common/driver.rb @@ -320,8 +320,21 @@ def ref attr_reader :bridge def create_bridge(caps:, url:, http_client: nil) - klass = caps['webSocketUrl'] ? Remote::BiDiBridge : Remote::Bridge - klass.new(http_client: http_client, url: url).tap do |bridge| + if caps['webSocketUrl'] + ws_options = + { + response_timeout: caps['wsResponseTimeout'], + response_interval: caps['wsResponseInterval'] + }.compact + + klass = Remote::BiDiBridge + bridge_opts = { http_client: http_client, url: url, ws_options: ws_options } + else + klass = Remote::Bridge + bridge_opts = { http_client: http_client, url: url } + end + + klass.new(**bridge_opts).tap do |bridge| bridge.create_session(caps) end end diff --git a/rb/lib/selenium/webdriver/remote/bidi_bridge.rb b/rb/lib/selenium/webdriver/remote/bidi_bridge.rb index c95ddec538f85..5ec25374a8623 100644 --- a/rb/lib/selenium/webdriver/remote/bidi_bridge.rb +++ b/rb/lib/selenium/webdriver/remote/bidi_bridge.rb @@ -23,10 +23,15 @@ module Remote class BiDiBridge < Bridge attr_reader :bidi + def initialize(url:, http_client: nil, ws_options: {}) + super(url: url, http_client: http_client) + @ws_options = ws_options + end + def create_session(capabilities) super socket_url = @capabilities[:web_socket_url] - @bidi = Selenium::WebDriver::BiDi.new(url: socket_url) + @bidi = Selenium::WebDriver::BiDi.new(url: socket_url, options: @ws_options) end def get(url) From b81bfed28ed894c90c31ca4f0fbea1354ee4e9a8 Mon Sep 17 00:00:00 2001 From: aguspe Date: Thu, 17 Jul 2025 18:13:36 +0200 Subject: [PATCH 4/6] Add tests and modify options --- rb/lib/selenium/webdriver/common/driver.rb | 4 ++-- rb/lib/selenium/webdriver/common/options.rb | 2 +- .../webdriver/bidi/browsing_context_spec.rb | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/rb/lib/selenium/webdriver/common/driver.rb b/rb/lib/selenium/webdriver/common/driver.rb index 32c40655f1e14..6b7c8a2da8586 100644 --- a/rb/lib/selenium/webdriver/common/driver.rb +++ b/rb/lib/selenium/webdriver/common/driver.rb @@ -323,8 +323,8 @@ def create_bridge(caps:, url:, http_client: nil) if caps['webSocketUrl'] ws_options = { - response_timeout: caps['wsResponseTimeout'], - response_interval: caps['wsResponseInterval'] + response_timeout: caps[:'ws:response_timeout'], + response_interval: caps[:'ws:response_interval'] }.compact klass = Remote::BiDiBridge diff --git a/rb/lib/selenium/webdriver/common/options.rb b/rb/lib/selenium/webdriver/common/options.rb index 1297f386e15e8..0086876ea2b61 100644 --- a/rb/lib/selenium/webdriver/common/options.rb +++ b/rb/lib/selenium/webdriver/common/options.rb @@ -26,7 +26,7 @@ class Options GRID_OPTIONS = %i[enable_downloads].freeze - WEBSOCKET_OPTIONS = %i[ws_response_timeout ws_response_interval].freeze + WEBSOCKET_OPTIONS = %i[ws:response_timeout ws:response_interval].freeze class << self attr_reader :driver_path diff --git a/rb/spec/integration/selenium/webdriver/bidi/browsing_context_spec.rb b/rb/spec/integration/selenium/webdriver/bidi/browsing_context_spec.rb index bcad86441d1bc..803ef2b527459 100644 --- a/rb/spec/integration/selenium/webdriver/bidi/browsing_context_spec.rb +++ b/rb/spec/integration/selenium/webdriver/bidi/browsing_context_spec.rb @@ -132,6 +132,22 @@ class BiDi browsing_context.activate expect(driver.execute_script('return document.hasFocus();')).to be_truthy end + + it 'times out if a bidi command takes too long to receive a response' do + reset_driver!(web_socket_url: true, 'ws:response_timeout': 1) do |driver| + expect { + driver.navigate.to url_for('sleep?time=2') + }.to raise_error(Selenium::WebDriver::Error::TimeoutError) + end + end + + it 'does not time out if a bidi command is fast enough' do + reset_driver!(web_socket_url: true, 'ws:response_timeout': 5) do |driver| + expect { + driver.navigate.to url_for('sleep?time=1') + }.not_to raise_error + end + end end end # BiDi end # WebDriver From 6d363dd56aaf1c4d0e09ad458265c17131b6d139 Mon Sep 17 00:00:00 2001 From: aguspe Date: Sat, 19 Jul 2025 17:41:28 +0200 Subject: [PATCH 5/6] fix test --- rb/lib/selenium/webdriver/common/driver.rb | 20 ++++--------------- rb/lib/selenium/webdriver/common/options.rb | 4 +++- .../selenium/webdriver/remote/bidi_bridge.rb | 13 ++++++------ .../webdriver/bidi/browsing_context_spec.rb | 14 +++---------- 4 files changed, 17 insertions(+), 34 deletions(-) diff --git a/rb/lib/selenium/webdriver/common/driver.rb b/rb/lib/selenium/webdriver/common/driver.rb index 6b7c8a2da8586..e07e86cdf99b9 100644 --- a/rb/lib/selenium/webdriver/common/driver.rb +++ b/rb/lib/selenium/webdriver/common/driver.rb @@ -320,23 +320,11 @@ def ref attr_reader :bridge def create_bridge(caps:, url:, http_client: nil) - if caps['webSocketUrl'] - ws_options = - { - response_timeout: caps[:'ws:response_timeout'], - response_interval: caps[:'ws:response_interval'] - }.compact - - klass = Remote::BiDiBridge - bridge_opts = { http_client: http_client, url: url, ws_options: ws_options } - else - klass = Remote::Bridge - bridge_opts = { http_client: http_client, url: url } - end + klass = caps['webSocketUrl'] ? Remote::BiDiBridge : Remote::Bridge - klass.new(**bridge_opts).tap do |bridge| - bridge.create_session(caps) - end + bridge = klass.new(http_client: http_client, url: url) + bridge.create_session(caps) + bridge end def service_url(service) diff --git a/rb/lib/selenium/webdriver/common/options.rb b/rb/lib/selenium/webdriver/common/options.rb index 0086876ea2b61..e89f0b51a33e8 100644 --- a/rb/lib/selenium/webdriver/common/options.rb +++ b/rb/lib/selenium/webdriver/common/options.rb @@ -26,7 +26,7 @@ class Options GRID_OPTIONS = %i[enable_downloads].freeze - WEBSOCKET_OPTIONS = %i[ws:response_timeout ws:response_interval].freeze + WEBSOCKET_OPTIONS = %i[web_socket_timeout web_socket_interval].freeze class << self attr_reader :driver_path @@ -110,6 +110,8 @@ def as_json(*) downloads = options.delete(:enable_downloads) options['se:downloadsEnabled'] = downloads unless downloads.nil? + options['ws:response_timeout'] = options.delete(:web_socket_timeout) if options[:web_socket_timeout] + options['ws:response_interval'] = options.delete(:web_socket_interval) if options[:web_socket_interval] w3c_options = process_w3c_options(options) browser_options = self.class::CAPABILITIES.each_with_object({}) do |(capability_alias, capability_name), hash| diff --git a/rb/lib/selenium/webdriver/remote/bidi_bridge.rb b/rb/lib/selenium/webdriver/remote/bidi_bridge.rb index 5ec25374a8623..aa3a52ea2aa07 100644 --- a/rb/lib/selenium/webdriver/remote/bidi_bridge.rb +++ b/rb/lib/selenium/webdriver/remote/bidi_bridge.rb @@ -23,15 +23,16 @@ module Remote class BiDiBridge < Bridge attr_reader :bidi - def initialize(url:, http_client: nil, ws_options: {}) - super(url: url, http_client: http_client) - @ws_options = ws_options - end - def create_session(capabilities) super socket_url = @capabilities[:web_socket_url] - @bidi = Selenium::WebDriver::BiDi.new(url: socket_url, options: @ws_options) + + ws_options = { + response_timeout: capabilities['ws:responseTimeout'], + response_interval: capabilities['ws:responseInterval'] + }.compact + + @bidi = Selenium::WebDriver::BiDi.new(url: socket_url, options: ws_options) end def get(url) diff --git a/rb/spec/integration/selenium/webdriver/bidi/browsing_context_spec.rb b/rb/spec/integration/selenium/webdriver/bidi/browsing_context_spec.rb index 803ef2b527459..03a0155bb8ecf 100644 --- a/rb/spec/integration/selenium/webdriver/bidi/browsing_context_spec.rb +++ b/rb/spec/integration/selenium/webdriver/bidi/browsing_context_spec.rb @@ -133,21 +133,13 @@ class BiDi expect(driver.execute_script('return document.hasFocus();')).to be_truthy end - it 'times out if a bidi command takes too long to receive a response' do - reset_driver!(web_socket_url: true, 'ws:response_timeout': 1) do |driver| + it 'times out if a command takes too long' do + reset_driver!(web_socket_url: true, web_socket_timeout: 0.1, web_socket_interval: 1) do |driver| expect { - driver.navigate.to url_for('sleep?time=2') + driver.navigate.to url_for('sleep?time=0.2') }.to raise_error(Selenium::WebDriver::Error::TimeoutError) end end - - it 'does not time out if a bidi command is fast enough' do - reset_driver!(web_socket_url: true, 'ws:response_timeout': 5) do |driver| - expect { - driver.navigate.to url_for('sleep?time=1') - }.not_to raise_error - end - end end end # BiDi end # WebDriver From 30fa9b8ac7c795e1f12f2392b9c7abbec3e89d02 Mon Sep 17 00:00:00 2001 From: aguspe Date: Sat, 19 Jul 2025 20:09:25 +0200 Subject: [PATCH 6/6] rollback driver changes --- rb/lib/selenium/webdriver/common/driver.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/rb/lib/selenium/webdriver/common/driver.rb b/rb/lib/selenium/webdriver/common/driver.rb index e07e86cdf99b9..94a29513e2752 100644 --- a/rb/lib/selenium/webdriver/common/driver.rb +++ b/rb/lib/selenium/webdriver/common/driver.rb @@ -321,10 +321,9 @@ def ref def create_bridge(caps:, url:, http_client: nil) klass = caps['webSocketUrl'] ? Remote::BiDiBridge : Remote::Bridge - - bridge = klass.new(http_client: http_client, url: url) - bridge.create_session(caps) - bridge + klass.new(http_client: http_client, url: url).tap do |bridge| + bridge.create_session(caps) + end end def service_url(service)